• الإعلانات

    • فيصل الحربي

      تسجيل عضوية جديدة في المنتدى   01/31/2016

      السلام عليكم ورحمة الله وبركاته  عزيزي العضو الجديد :  حاليا رسالة الإيميل لتأكيد صحة إيميلكم تذهب للبريد العشوائي ( جاري حل المشكلة )  فإذا لم تجد رسالة التحقق من إيميلكم في صندوق الوارد لديكم إتجه للبريد العشوائي ( JUNK)  وقم بتفعيل إشتراككم من هناك   

reem elsaba

اعضاء جدد
  • عدد المشاركات

    33
  • تاريخ الانضمام

  • تاريخ اخر زياره

السمعه بالموقع

0 عادي

عن reem elsaba

  • الرتبة
    عضو جديد

معلومات الملف الشخصي

  • الجنس أنثى
  • الدولة : أرض الرباط
  • اهتمامات تصميم فوتوشوب باحتراف
  1. Cryptography project

    الله يسامحك اخي والله هذه الخوارزميات بمجهودي الشخصي وكانت مطلوبة معنا واجبات للمادة طول الفصل والمشروع النهائي ربط الخوارزميات يلي اخذناها و عملتيها بان تشفر بدل النص ملف ولكن طبعا انا خبرتي صفر بالملفات عالعموم بتشكرك عالرد المحفز لي جدا و يسعدني ان اقول لك ان الموضوع أرغب في حذفه :wacko: تشكرات لحضرتكم مرة تانية أستفدنا منكم كثير والمشروع لو بدو ييجي منكم أنا ماعاد بدي ياه
  2. Cryptography project

    أخي الله يكرمك أنا جهازي مضروب ومابيفتح الا ملفات وورد و بوربوينت وحتى برنامج الضغط خربان عندي وناطرة يوم ال22 اخلص مشان افرمت لان انا هلأ بحاجة الجهاز وماعندي وقت افرمت مشان هيك ماعم اعرف اشتغل اي شي بهالمشروع وماعندي وقت اشتغل بقى المطلوب ان نعمل برنامج لتشفير ملف او فك تشفيره حسب خوارزميات التشفير يلي معنا بالكورس وطبعا كان معنا واجب بعض هاي الخوارزميات يلي انا منزلاهم وهنن شغالين ان شاء الله بس هلأ المطلوب اربط الخوارزميات بواجهة البرنامج الموجودة في الموضوع الاصلي وانا رح ابعتلك المطلوب منا بالضبط أخي الله يوفقك اذا فيك تخلصني من هالورطة والا والله برسب بالمادة لان المشروع عليه نص العلامة :( :( :(
  3. Cryptography project

    شو يا جماعة الخير على اساس انكن بتقدموا مساعدات للمحتاج , وينكن؟ :wacko: :wacko:
  4. Cryptography project

    :wacko: :wacko:
  5. Cryptography project

    السلام عليكم ياريت اي حد بيفهم بالجافا كثير منيح يساعدني بهالمشروع لان عليي بحث تخرج ومشروع تخرج بالـ Expert System ومش ملحقة اعمل المشروع و المشروع اليوم الساعة 9المسا اخر موعد لتسليمه والمشروع مطلوب عمل تشفير لملف موجود عندي عالـ جهاز و مطلوب مننا عمل تشفير 4 خوارزميات للتشفير عالأقل والنت بينز عندي ضرب بعد مشروع الويب سيرفيس وطبعا الشغلة بدها فرمتة للجهاز و لكن يوم الخميس عندي اول امتحان ومافيني فرمت الجهاز بقى ساعدوني الله يكرمكم وهون في رابط لصورة الواجهة للـ المشروع و قمت بعمل بعض الخوارزميات لـ RSA /* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.math.BigInteger ; import java.util.Random ; public class RSA { BigInteger one = new BigInteger("1") ; Random random = new Random() ; static BigInteger publicKey , privateKey , n ; // Create RSA function RSA(int bits) { BigInteger p = BigInteger .probablePrime(bits, random) ; BigInteger q = BigInteger .probablePrime(bits, random) ; n = p.multiply(q) ; BigInteger z = (p.subtract(one)).multiply((q.subtract(one))) ; publicKey = new BigInteger("65537") ; privateKey = publicKey.modInverse(z) ; } //Converte string to integer static BigInteger toBigInteger(String str) { byte [] b = new byte[str.length()] ; for(int i = 0 ; i<str.length(); i++) b[i] = (byte)str.charAt(i); return new BigInteger(b) ; } //Converte integer to string static String intToString(BigInteger n) { byte [] b = n.toByteArray() ; StringBuffer s = new StringBuffer() ; for(int i = 0 ; i<b.length; i++) s.append((char)b[i]) ; return s.toString() ; } //Encrypt function static BigInteger encryp(String plain , BigInteger e) { BigInteger c = toBigInteger(plain).modPow(e,n) ; return c; } //Decrypt function static BigInteger decrype(BigInteger cygher , BigInteger d) { BigInteger m = cygher.modPow(d,n) ; return m; } //The main function public static void main(String [] args) { RSA rsa = new RSA(234) ; String m = "Hello I need to encrypt this text" ; BigInteger c = encryp(m,publicKey) ; System.out.println(c) ; BigInteger plain = decrype(c,privateKey) ; System.out.println(intToString(plain)) ; } } وهي الـ caesar /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package cesars; import java.util.Scanner; public class caesar3 { private static input input; private static input output; public static void main(String[] args) throws java.io.IOException { // read input from console System.out.println("Enter Plaintext: "); // prompt Scanner consoleInput = new Scanner(System.in); // set up scanner String input = consoleInput.nextLine(); // get line from console // Note - if you want to read an integer from the console, // use nextInt - see documentation for Scanner char chars[] = input.toCharArray(); // break String up into chars for (int i=0; i < chars.length; i++) // iterate through the chars chars[i] = Encrypt(chars[i]); // update cipher to each char String output = new String(chars); // convert back into a String // write out String System.out.println("PlainText: "+input); System.out.println("CipherText: "+output); } public static char Encrypt (char x) // function to apply the cipher to a char { if(Character.isLetter(x)) { if(Character.isLowerCase(x)) { int ascii_x = (int) x; ascii_x -=97; ascii_x = (ascii_x+3)%26; return (char) (ascii_x + 97); } else{ int ascii_x = (int) x; ascii_x -=65; ascii_x = (ascii_x+3)%26; return (char) (ascii_x + 65); } }else return x; } public static void u(String[] args) throws java.io.IOException { System.out.println("Enter Ciphertext: "); // prompt Scanner consoleOutput = new Scanner(System.in); // set up scanner String Output = consoleOutput.nextLine(); char chars[] = output.toCharArray(); // break String up into chars for (int i=chars.length; i > chars.length; i--) // iterate through the chars chars[i] = Decrypt(chars[i]); // update cipher to each char String output = new String(chars); // convert back into a String // write out String //System.out.println("CiText: "+input); System.out.println("CipherText: "+output); } public static char Decrypt (char x) // function to apply the cipher to a char { int temp; if(Character.isLetter(x)) { if(Character.isUpperCase(x)) { temp= (int)x; temp= temp +97; temp = (x-3)%26; return (char) (temp - 97); } else{ temp = (int)x; temp=temp+65; temp = (temp-3)%26; return (char) (temp-65); } }else return x; } } وهي ال DES ملف الـ arrayprinter /* * * Please Visit us at www.codemiles.com * * This Program was Developed by www.codemiles.com forums Team * * Please Don't Remove This Comment * */ public class arrayprinter { /** Creates a new instance of arrayprinter */ public arrayprinter() { } public static void printarray(String[][] arr,String label) { DesPanel.StepsText.append("-- "+label+" -- "+'\n'); //System.out.println("-- "+label+" -- "); for(int i=0;i<arr.length ;i++) { DesPanel.StepsText.append("| "); for(int j=0;j<arr[0].length;j++) { DesPanel.StepsText.append(arr[i][j]+" "); } DesPanel.StepsText.append("| "+'\n'); } } } /* * * Please Visit us at www.codemiles.com * * This Program was Developed by www.codemiles.com forums Team * * Please Don't Remove This Comment * */ وهي ملف الـ SBox /* * * Please Visit us at www.codemiles.com * * This Program was Developed by www.codemiles.com forums Team * * Please Don't Remove This Comment * */ public class SBox { /** Creates a new instance of SBox */ public SBox() { } public void DoDecimal(int [] num){ dec1[0]=num[0]; dec1[1]=num[5]; row=1*dec1[1]+2*dec1[0]; //System.out.print("-------"+row); } public void DoFourDecimal(int [] num){ dec2[0]=num[1]; dec2[1]=num[2]; dec2[2]=num[3]; dec2[3]=num[4]; col=1*dec2[3]+2*dec2[2]+dec2[1]*4+dec2[0]*8; //System.out.print("***********"+col); } public void SelectSBox(int choice, int row, int col){ switch(choice){ case 0: SBox_Result[index1]=SBOX1[row][col]; index1++; break; case 1: SBox_Result[index1]=SBOX2[row][col]; index1++; break; case 2: SBox_Result[index1]=SBOX3[row][col]; index1++; break; case 3: SBox_Result[index1]=SBOX4[row][col]; index1++; break; case 4: SBox_Result[index1]=SBOX5[row][col]; index1++; break; case 5: SBox_Result[index1]=SBOX6[row][col]; index1++; break; case 6: SBox_Result[index1]=SBOX7[row][col]; index1++; break; case 7: SBox_Result[index1]=SBOX8[row][col]; index1++; break; } } public void make32bit(int num){ int num1 = 0,num2,num3; num1=num; System.out.println("Code "); for(int i=0; i<4; i++){ num2=num1%2; num3=num1/2; num1=num3; after_SBox[index2]=num2; System.out.print(after_SBox[index2]); index2++; } } public void Reverse(int [] num){ int count=0; int fix=3; int temp1,temp2; while(count!=32){ for(int i=0; i<2; i++){ temp1=num[count+i]; num[count+i]=num[fix-(count+i)]; num[fix-(count+i)]=temp1; } fix+=8; count+=4; } } public void Fill_P() { int index=0; for(int row=0;row<8; row++){ for(int col=0; col<4; col++){ store_num[index]=P[row][col]; index++; } } } public void Do_P(int [] after_SBox, int [] func_out ){ int temp=0; int i=0; int loop=0; int check=0; while(check!=32){ temp=store_num[i]; if(temp==loop){ func_out[check]=after_SBox[loop-1]; loop=0; check++; i++; } loop++; } } public void DoSBox(int [] XOR_Out, int [] S_Out){ DesPanel.StepsText.append("*********S-Box Stages********* "+'\n'); int count=0; int choice=0; int i; index=0; while(count!=48){ for(i=0; i<6; i++) { temp[i]=XOR_Out[i+count]; } System.out.println(" "); DoDecimal(temp); // System.out.println(); DoFourDecimal(temp); // System.out.println(); SBox_row[index]=row; SBox_col[index]=col; SelectSBox(choice,SBox_row[index],SBox_col[index]); System.out.println(index+" ="+SBox_Result[index]+"ROW "+row+" COL "+col); make32bit(SBox_Result[index]); index++; choice++; count+=6; } Reverse(after_SBox); index=0; for(int d=0 ; d<4; d++){ for(int j=0; j<8; j++){ after_SBoxs[d][j]=Integer.toString(after_SBox[index]); index++; } } index=0; arrayprinter.printarray(after_SBoxs,"Final Result After SBoxes"); Fill_P(); Do_P(after_SBox,func_out); for(int d=0 ; d<4; d++){ for(int j=0; j<8; j++){ func_outS[d][j]=Integer.toString(func_out[index]); index++; } } index=0; arrayprinter.printarray(func_outS,"After IP"); for(int j=0; j<32; j++) S_Out[j]=func_out[j]; // System.out.println(); } private int index=0; private int[] func_out=new int[32]; private int [] store_num=new int[32]; private String text48; private int [] after_SBox=new int[32]; private int index1=0; private int index2=0; private int row=0; private int col=0; private int [] SBox_Result=new int [8]; private int[] SBox_row=new int[8]; private int[] SBox_col= new int[8]; private int [] dec1=new int[2]; private int [] dec2=new int[4]; private int[] temp =new int[6]; private int [][] SBOX1= {{14 ,4 ,13 ,1 ,2 ,15 ,11 ,8 ,3 ,10 ,6 ,12 ,5 ,9 ,0 ,7}, {0 ,15 ,7 ,4 ,14 ,2 ,13 ,1 ,10 ,6 ,12 ,11 ,9 ,5 ,3 ,8}, {4 ,1 ,14 ,8 ,13 ,6 ,2 ,11 ,15 ,12 ,9 ,7 ,3 ,10 ,5 ,0}, {15, 12, 8, 2, 4, 9, 1, 7 ,5, 11, 3, 14, 10, 0, 6, 13} }; private int [][] SBOX2= {{15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12 ,0, 5, 1}, {3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9 ,11, 5}, {0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15}, {13 ,8 ,10 ,1 ,3 ,15 ,4 ,2 ,11 ,6 ,7 ,12 ,0 ,5 ,14 ,9} }; private int [][] SBOX3={{10 ,0 ,9 ,14 ,6 ,3 ,15 ,5 ,1 ,13 ,12 ,7 ,11 ,4 ,2 ,8}, {13, 7, 0, 9, 3, 4, 6, 10, 2 ,8 ,5 ,14, 12, 11, 15, 1}, {13, 6, 4, 9, 8 ,15 ,3 ,0, 11, 1, 2, 12, 5, 10, 14, 7}, {1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12} }; private int [][] SBOX4={{7 ,13 ,14 ,3 ,0 ,6 ,9 ,10 ,1 ,2 ,8 ,5 ,11 ,12 ,4 ,15}, {13 ,8 ,11 ,5, 6 ,15, 0 ,3 ,4 ,7 ,2 ,12 ,1 ,10 ,14 ,9}, {10, 6, 9, 0, 12, 11, 7 ,13, 15, 1, 3, 14, 5, 2, 8, 4}, {3, 15, 0, 6, 10, 1, 13, 8, 9, 4 ,5 ,11 ,12, 7, 2, 14} }; private int [][] SBOX5={{2 ,12 ,4 ,1 ,7 ,10 ,11 ,6 ,8 ,5 ,3 ,15 ,13 ,0 ,14 ,9}, {14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3 ,9 ,8 ,6}, {4 ,2, 1, 11, 10, 13, 7 ,8 ,15, 9, 12, 5, 6, 3, 0, 14}, {11, 8, 12 ,7, 1, 14 ,2 ,13 ,6 ,15, 0 ,9, 10, 4, 5, 3} }; private int [][] SBOX6={{12 ,1 ,10 ,15, 9 ,2, 6 ,8 ,0 ,13 ,3 ,4 ,14 ,7 ,5 ,11}, {10, 15, 4 ,2 ,7 ,12 ,9, 5, 6, 1, 13 ,14 ,0, 11, 3 ,8}, {9, 14, 15, 5, 2 ,8 ,12, 3, 7 ,0 ,4 ,10, 1, 13 ,11 ,6}, {4, 3, 2, 12, 9, 5, 15 ,10 ,11, 14, 1, 7, 6, 0, 8, 13} }; private int [][] SBOX7={ {4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7 ,5 ,10 ,6 ,1}, {13, 0, 11, 7, 4, 9, 1, 10, 14 ,3 ,5, 12, 2, 15, 8, 6}, {1, 4, 11, 13, 12, 3, 7 ,14, 10, 15, 6, 8, 0, 5, 9, 2}, {6, 11, 13, 8 ,1 ,4, 10, 7, 9, 5 ,0 ,15 ,14, 2, 3, 12} }; private int [][] SBOX8={ {13, 2, 8, 4, 6, 15, 11, 1 ,10, 9, 3, 14, 5, 0, 12, 7}, {1, 15, 13, 8 ,10, 3 ,7 ,4 ,12, 5, 6 ,11, 0, 14, 9, 2}, {7, 11, 4, 1 ,9 ,12 ,14 ,2 ,0 ,6 ,10, 13 ,15 ,3 ,5 ,8}, {2, 1, 14, 7 ,4 ,10, 8 ,13, 15, 12, 9, 0, 3, 5, 6, 11} }; private int [][] P={{16 ,7 ,20 ,21}, {29, 12, 28, 17}, {1, 15, 23, 26}, {5, 18, 31, 10}, {2 ,8 ,24 ,14}, {32, 27, 3, 9}, {19, 13, 30, 6}, {22, 11, 4, 25} }; private String after_SBoxs [][]= new String[4][8]; private String func_outS [][]= new String[4][8]; } /* * * Please Visit us at www.codemiles.com * * This Program was Developed by www.codemiles.com forums Team * * Please Don't Remove This Comment * */ وهي ملف الـ Permutation /* * * Please Visit us at www.codemiles.com * * This Program was Developed by www.codemiles.com forums Team * * Please Don't Remove This Comment * */ class Permutation { /** Creates a new instance of Permutation */ public Permutation() { } public void FillPermutation() { int index=0; for(int row=0;row<8; row++){ for(int col=0; col<8; col++){ store_num[index]=permutation[row][col];/// from 2D to 1 D index++; } } } public void FillInversePermutation() { int index=0; for(int row=0;row<8; row++){ for(int col=0; col<8; col++){ store_num[index]=inverperm[row][col];/// from 2D to 1 D index++; } } } public void DoIP(int [] perm_in, int [] perm_out) { int temp=0; int i=0; int loop=0; int check=0; while(perm_in.length!=check){ temp=store_num[i]; if(temp==loop){ perm_out[check]=perm_in[loop-1]; loop=0; check++; i++; } loop++; } System.out.println("The Permutted output"); for(int j=0; j<perm_out.length; j++){ System.out.print(perm_out[j]); } int index=0; for(int g=0; g<8; g++){ for(int j=0; j<8; j++){ permS[g][j]=Integer.toString(perm_in[index]); index++; } } arrayprinter.printarray(permS,"After Initial Permutation"); } public void DoInverseIP(int [] perm_in, int [] perm_out) { int temp=0; int i=0; int loop=0; int check=0; while(perm_in.length!=check){ temp=store_num[i]; if(temp==loop){ perm_out[check]=perm_in[loop-1]; loop=0; check++; i++; } loop++; } int index=0; for(int d=0; d<4;d++){ for(int j=0; j<8; j++){ newBlock64[d][j]=Integer.toString(perm_out[index]); index++; } } arrayprinter.printarray(newBlock64,"After IP"); } private int[] store_num= new int[64]; private int permutation[][]={{58,50,42,34,26,18,10,2}, {60, 52, 44 ,36, 28, 20, 12 ,4}, {62 ,54 ,46 ,38 ,30 ,22 ,14 ,6}, {64 ,56, 48, 40, 32, 24 ,16, 8}, {57 ,49 ,41 ,33 ,25 ,17 ,9 ,1}, {59 ,51, 43 ,35 ,27 ,19 ,11, 3}, {61 ,53 ,45, 37, 29 ,21 ,13 ,5}, {63 ,55 ,47 ,39 ,31 ,23, 15, 7}}; private int inverperm[][]= {{40 , 8 ,48, 16, 56, 24, 64, 32}, {39, 7, 47, 15, 55 ,23, 63, 31}, {38 ,6 ,46 ,14, 54, 22 ,62, 30}, {37 ,5 ,45, 13, 53 ,21, 61, 29}, {36 ,4 ,44 ,12 ,52 ,20 ,60 ,28}, {35 ,3 ,43 ,11, 51, 19 ,59 ,27}, {34 ,2 ,42, 10 ,50, 18 ,58, 26}, {33, 1 ,41, 9 ,49, 17, 57, 25}}; private String permS[][] = new String[8][8]; private String newBlock64 [][]= new String[4][8]; } /* * * Please Visit us at www.codemiles.com * * This Program was Developed by www.codemiles.com forums Team * * Please Don't Remove This Comment * */ وهي ملف الـ KeyGen /* * * Please Visit us at www.codemiles.com * * This Program was Developed by www.codemiles.com forums Team * * Please Don't Remove This Comment * */ public class KeyGen { /** Creates a new instance of KeyGen */ public KeyGen() { } public void FillPC_1() { int index=0; for(int row=0;row<8; row++){ for(int col=0; col<7; col++){ store_num[index]=PC_1[row][col]; index++; } } } public void FillPC_2() { int index=0; for(int row=0;row<8; row++){ for(int col=0; col<6; col++){ store_num1[index]=PC_2[row][col]; index++; } } } public void DoPC_1(int [] key_in, int [] key_out) { int temp=0; int i=0; int loop=0; int check=0; while(check!=56){ temp=store_num[i]; if(temp==loop){ key_out[check]=key_in[loop-1]; loop=0; check++; i++; } loop++; } System.out.println("The Permutted key"); for(int j=0; j<key_out.length; j++){ System.out.print(key_out[j]); } int index=0; for(int g=0; g<7; g++){ for(int j=0; j<8; j++){ keyS[g][j]=Integer.toString(key_out[index]); index++; } } arrayprinter.printarray(keyS,"After PC-1"); } public void DoPC_2(int [] key_in, int [] key_out) { int temp=0; int i=0; int loop=0; int check=0; while(check!=48){ temp=store_num1[i]; if(temp==loop){ key_out[check]=key_in[loop-1]; loop=0; check++; i++; } loop++; } int index=0; for(int g=0; g<6; g++){ for(int j=0; j<8; j++){ finalS[g][j]=Integer.toString(key_out[index]); index++; } } arrayprinter.printarray(finalS,"After PC-2"); index=0; } public void DoSegementation(int [] key_out,int [] C, int[] D){ int index=0; for(int i=0; i<28; i++) C[i]=key_out[i]; for(int i=28; i<56; i++){ D[index]=key_out[i]; index++; } index=0; for(int g=0; g<4; g++){ for(int j=0; j<7; j++){ cS[g][j]=Integer.toString(key_out[index]); index++; } } for(int g=0; g<4; g++){ for(int j=0; j<7; j++){ dS[g][j]=Integer.toString(key_out[index]); index++; } } index=0; arrayprinter.printarray(cS,"Segment Key to C part"); arrayprinter.printarray(dS,"Segment Key to D part"); } public void Do_OneLeftShitf(int[] side1, int []side2){ int temp=side1[0]; for(int i=1; i<side1.length; i++){ side1[i-1]=side1[i]; } side1[side1.length-1]=temp; temp=side2[0]; for(int i=1; i<side2.length; i++){ side2[i-1]=side2[i]; } side2[side2.length-1]=temp; System.out.println("After One left shift"); for(int j=0; j<side1.length; j++){ System.out.print(side1[j]); } } private int[] store_num= new int[56]; private int[] store_num1= new int[48]; private int[][] PC_1={{57 ,49 ,41 ,33 ,25 ,17 ,9}, {1, 58, 50, 42, 34, 26, 18}, {10, 2,59, 51, 43, 35, 27}, {19, 11, 3, 60, 52, 44, 36}, {63, 55, 47, 39, 31, 23, 15}, {7, 62, 54, 46, 38, 30, 22}, {14, 6, 61, 53, 45, 37, 29}, {21, 13, 5 ,28, 20, 12, 4} }; private int[][] PC_2={{14, 17, 11, 24, 1, 5}, {3, 28, 15, 6, 21, 10}, {23, 19, 12, 4,26, 8}, {16, 7, 27, 20, 13, 2}, {41, 52, 31, 37, 47, 55}, {30, 40, 51, 45, 33, 48}, {44, 49, 39, 56, 34, 53}, {46, 42, 50, 36, 29, 32} }; private String key; private String keyS[][]= new String[7][8]; private String cS[][] = new String [4][7]; private String dS[][] = new String [4][7]; private String finalS[][] = new String [6][8]; } /* * * Please Visit us at www.codemiles.com * * This Program was Developed by www.codemiles.com forums Team * * Please Don't Remove This Comment * */ وهي ملف الـ ESTable /* * * Please Visit us at www.codemiles.com * * This Program was Developed by www.codemiles.com forums Team * * Please Don't Remove This Comment * */ public class ESTable { /** Creates a new instance of ESTable */ public ESTable() { } public void FillETable() { int index=0; for(int row=0;row<8; row++){ for(int col=0; col<6; col++){ store_num[index]=ETable[row][col]; index++; } } } public void DoETable(int [] Right_in, int [] Right_out){ int temp=0; int i=0; int loop=0; int check=0; while(check!=48){ temp=store_num[i]; if(temp==loop){ Right_out[check]=Right_in[loop-1]; loop=0; check++; i++; } loop++; } System.out.println(" "); System.out.print(" E- table "); for(int j=0;j<48;j++) System.out.print(Right_out[j]); int index=0; for(int g=0; g<6; g++){ for(int j=0; j<8; j++){ RightS[g][j]=Integer.toString(Right_out[index]); index++; } } arrayprinter.printarray(RightS,"After E-Table"); index=0; } private int[] store_num= new int[48]; private int [][] ETable= {{32, 1, 2, 3, 4, 5}, {4 ,5 ,6 ,7 ,8 ,9}, {8 ,9 ,10 ,11 ,12 ,13}, {12 ,13 ,14 ,15 ,16 ,17}, {16, 17, 18, 19, 20, 21}, {20, 21, 22, 23, 24, 25}, {24, 25, 26, 27, 28, 29}, {28, 29, 30, 31, 32, 1}}; private String RightS[][] = new String[6][8]; } /* * * Please Visit us at www.codemiles.com * * This Program was Developed by www.codemiles.com forums Team * * Please Don't Remove This Comment * */ وهي ملف الـ encrypt /* * * Please Visit us at www.codemiles.com * * This Program was Developed by www.codemiles.com forums Team * * Please Don't Remove This Comment * */ import java.util.Scanner; public class encrypt { /** Creates a new instance of encrypt */ public encrypt( String Plaintext, String Key) { PlainText=Plaintext; keyword=Key; } public String CheckLenPlain(String plain){ if(plain.length()%8!=0) { int len=8-plain.length()%8; for(int i=0; i<len; i++) plain=plain.concat("*"); } else { return plain; } return plain; } public void DoEncrpyt_Plaintext(String plain) { for(int i=0;i<8&&i<plain.length();i++) { block[i]=getBinaryBits(plain.charAt(i));// 2D array [8][8] } int index=0; for(int i=0; i<8; i++){ for(int j=0; j<8;j++){ perm[index]=(int)block[i][j]; blockS[i][j]=Integer.toString((int)block[i][j]); index++; } } arrayprinter.printarray(blockS,"PlainText Text in Binary"); DesPanel.StepsText.append("****************************************************************"+'\n'); } public void DoEncrpyt_keyword() { for(int i=0;i<8&&i<keyword.length();i++) { block[i]=getBinaryBits(keyword.charAt(i)); for(int j=0;j<8;j++) { blockS[i][j]=Integer.toString((int)block[i][j]); } // System.out.println(" "); } int index=0; for(int i=0; i<8; i++){ for(int j=0; j<8;j++){ key_in[index]=(int)block[i][j]; index++; } } arrayprinter.printarray(blockS,"KeyWord Text in Binary"); DesPanel.StepsText.append("****************************************************************"+'\n'); } public byte[] getBinaryBits(int ch) { byte[] bin=new byte[8]; int tag=1; for(int i=0;i<8;i++) { bin[7-i]=(byte)((ch&((tag<<i)))>>i); } return bin; } public void DoSegmentation(int[] perm_out){ int index=0; for(int i=0; i<32; i++) Left[i]=perm_out[i]; for(int i=32; i<64; i++){ Right[index]=perm_out[i]; index++; } index=0; for(int i=0; i<4;i++){ for(int j=0; j<8; j++){ LeftS[i][j]=Integer.toString(Left[index]); RightS[i][j]=Integer.toString(Right[index]); index++; } } arrayprinter.printarray(LeftS,"Left Part"); arrayprinter.printarray(RightS,"Right Part"); } public void XOR(int side1[], int [] side2,int [] result){ int index=0; for(int i=0; i<side1.length; i++){ if(side1[i]==side2[i]) result[index]=0; else result[index]=1; index++; } } public void FillC_D(){ int index=28; for(int i=0; i<28; i++) C_D[i]=C[i]; for(int i=0; i<28; i++){ C_D[index]=D[i]; index++; } } public void contancate() { int index=32; for(int i=0; i<32; i++) Block64[i]=Left[i]; for(int i=0; i<32; i++){ Block64[index]=Right[i]; index++; } } public void swap32() { int temp; for(int i=0;i<32;i++) { temp=Left[i]; Left[i]=Right[i]; Right[i]=temp; } ind=0; for(int i=0; i<4;i++){ for(int j=0; j<8; j++){ LeftS[i][j]=Integer.toString(Left[ind]); RightS[i][j]=Integer.toString(Right[ind]); ind++; } } arrayprinter.printarray(LeftS,"Left Part"); arrayprinter.printarray(RightS,"Right Part"); ind=0; } public static int[] getByteFromBits(int bits64[]) { // int ch[]=new int[8]; int index=0; System.out.println(); for(int i=0;i<8;i++) for(int j=1;j<=8;j++) { ch[i]+=(int)Math.pow(2,(8-j))*bits64[index]; index++; } return ch; } public void Chooser(int choice){ if(choice==1){ System.out.println("before One left shift " + index); for(int j=0; j<C.length; j++) System.out.print(C[j]); key.Do_OneLeftShitf(C,D); System.out.println(); System.out.println("After One left shift " + index); for(int j=0; j<C.length; j++) System.out.print(C[j]); } else{ for(int j=0; j<C.length; j++) System.out.print(C[j]); key.Do_OneLeftShitf(C,D); key.Do_OneLeftShitf(C,D); System.out.println(" LEFT= "); for(int j=0; j<C.length; j++) System.out.print(C[j]); System.out.println(" Right= "); for(int j=0; j<D.length; j++) System.out.print(D[j]); } } public void DoDecryption() { DesPanel.StepsText.append("************************DECIPHER***********************************"+'\n'); int start=0; int counter=0; int end=64; for(int f=0; f<PlainText.length()/8; f++){ int Round=1; for(int h=start; h<end; h++ ){ newBlock64_[counter]=Integer.parseInt(finalEncry.substring(h,h+1)); counter++; } DesPanel.StepsText.append("*********Block Number *********"+(f+1)+'\n'); ind=0; DesPanel.StepsText.append("*********Cipher Block In Round ********* "+ Round+'\n'); for(int d=0 ; d<8; d++){ for(int j=0; j<8; j++){ newBlock64_S[d][j]=Integer.toString(newBlock64[ind]); ind++; } } arrayprinter.printarray(newBlock64_S,"Cipher Block"); p= new Permutation(); p.FillPermutation();//step1 from 2D to 1D p.DoIP(newBlock64_,perm_out); DoSegmentation(perm_out); int adder=48; while(Round<=16) { DesPanel.StepsText.append("*********Round Number********* "+Round+'\n'); for(int i=0; i<48; i++) { reversedkey[i]=Integer.parseInt(key_reverse.substring((key_reverse.length()-adder)+i,(key_reverse.length()-adder)+i+1)); } System.out.println(); ESTable Etable = new ESTable(); Etable.FillETable();//step3 array from 2D to 1D Etable.DoETable(Right,Right_out);//step3 DesPanel.StepsText.append("*********Right Part XORED with Round Key********* "+Round+'\n'); XOR(Right_out,reversedkey,XOR_Out);//step1 ind=0; for(int g=0; g<6; g++){ for(int j=0; j<8; j++){ XORS[g][j]=Integer.toString(XOR_Out[ind]); ind++; } } arrayprinter.printarray(XORS,"XOR Result"); ind=0; SBox sbox= new SBox(); sbox.DoSBox(XOR_Out,after_SBox);//step2 32bits - include permitation DesPanel.StepsText.append("*********Left Part XORED with Output Function in Round********* "+Round+'\n'); XOR(Left,after_SBox,aft_XOR_fuc);//XOR for(int g=0; g<4; g++){ for(int j=0; j<8; j++){ aft_XOR_fucS[g][j]=Integer.toString(aft_XOR_fuc[ind]); ind++; } } ind=0; arrayprinter.printarray(aft_XOR_fucS,"XOR Result"); adder=adder+48; Round++; DesPanel.StepsText.append("*********Left=Right & Right=Left*********"+'\n'); for(int i=0;i<32;i++) { Left[i]=Right[i]; Right[i]=aft_XOR_fuc[i]; } } ind=0; for(int g=0; g<4; g++){ for(int j=0; j<8; j++){ LeftS[g][j]=Integer.toString(Right[ind]); RightS[g][j]=Integer.toString(aft_XOR_fuc[ind]); ind++; } } arrayprinter.printarray(LeftS,"Left Part"); arrayprinter.printarray(RightS,"Right Part"); DesPanel.StepsText.append("********After Swap Operation********* " +'\n'); swap32(); contancate(); System.out.println("/nBit Swap :"); for(int i=0;i<64;i++) { System.out.print(Block64[i]); } p.FillInversePermutation();//step1 from 2D to 1D p.DoInverseIP(Block64,newBlock64);//step1 -array System.out.println("The decyption code: "); for(int i=0; i<64; i++) { if(binDec==null) binDec=Integer.toString(newBlock64[i]); else binDec+=Integer.toString(newBlock64[i]); System.out.print(newBlock64[i]); } System.out.println(" "); ch=getByteFromBits(newBlock64); for(int i=0; i<8; i++){ System.out.print((char)ch[i]); if(finalDecry==null) finalDecry=Character.toString((char)ch[i]); else finalDecry+=Character.toString((char)ch[i]); } for(int i=0; i<8; i++) ch[i]=0; start=end; end=end+64; counter=0; } } public String getBinDec(){ return binDec; } public void DoEncryption(){ DesPanel.StepsText.append("************************CIPHER***********************************"+'\n'); DoEncrpyt_keyword(); int start=0; int end=8; PlainText=CheckLenPlain(PlainText); // System.out.println("PlainTETX: "+ PlainText.substring(start,start+9)); String temp; for(int f=0; f<PlainText.length()/8; f++){ temp=PlainText.substring(start,end); DoEncrpyt_Plaintext(temp); System.out.println("The Orginal Massage code: "); for(int i=0;i<64;i++) { if(binCi==null) binCi=Integer.toString(perm[i]); else binCi+=Integer.toString(perm[i]); System.out.print(perm[i]); } int Round=1; DesPanel.StepsText.append("*********Block Number *********"+(f+1)+'\n'); System.out.println(" "); Permutation p= new Permutation(); p.FillPermutation();//step1 from 2D to 1D p.DoIP(perm,perm_out);//step1 -array DoSegmentation(perm_out);//step2 to Left and Right // Here u will work on Right (32 Bits ) & Left 32 Bits //////////////////////////////////////////////////////////////////////// /////////////////////////////key Generation//////////////////////////// key.FillPC_1();//step1 -array System.out.println(); DesPanel.StepsText.append("*********Key Generation*********" +'\n'); key.DoPC_1(key_in,key_out);//step1 key.DoSegementation(key_out,C,D);//step2 while(Round<=16) { DesPanel.StepsText.append("*********Round Number********* "+Round+'\n'); int chooser=num_Left[index_chooser]; ESTable Etable = new ESTable(); Etable.FillETable();//step3 array from 2D to 1D Etable.DoETable(Right,Right_out);//step3 //////////////////////////////////////////////////////////////////////// System.out.println(); Chooser(chooser);//step 3 - shift System.out.println("Chooser = "+chooser); key.FillPC_2();//step4 array FillC_D();//step4 contacnate 56bits DesPanel.StepsText.append("*********Key For Round Number********* "+Round+'\n'); key.DoPC_2(C_D,final_key);//step4 here the key of Round 1 for(int i=0; i<48;i++) { if(key_reverse==null) key_reverse=Integer.toString(final_key[i]); else key_reverse+=Integer.toString(final_key[i]); } //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// DesPanel.StepsText.append("*********Right Part XORED with Round Key********* "+Round+'\n'); XOR(Right_out,final_key,XOR_Out);//step1 ind=0; for(int g=0; g<6; g++){ for(int j=0; j<8; j++){ XORS[g][j]=Integer.toString(XOR_Out[ind]); ind++; } } ind=0; arrayprinter.printarray(XORS,"XOR Result"); System.out.print("\nXOR :"); for(int j=0;j<48;j++) { System.out.print(XOR_Out[j]); } SBox sbox= new SBox(); sbox.DoSBox(XOR_Out,after_SBox);//step2 32bits - include permitation System.out.print("\nS-BOX :"); for(int j=0;j<32;j++) { System.out.print(after_SBox[j]); } System.out.print("\n AFter XOR :"); DesPanel.StepsText.append("*********Left Part XORED with Output Function in Round********* "+Round+'\n'); XOR(Left,after_SBox,aft_XOR_fuc);//XOR for(int g=0; g<4; g++){ for(int j=0; j<8; j++){ aft_XOR_fucS[g][j]=Integer.toString(aft_XOR_fuc[ind]); ind++; } } ind=0; arrayprinter.printarray(aft_XOR_fucS,"XOR Result"); for(int j=0;j<32;j++) { System.out.print(aft_XOR_fuc[j]); } Round++; index++; index_chooser++; DesPanel.StepsText.append("*********Left=Right & Right=Left*********"+'\n'); for(int i=0;i<32;i++) { Left[i]=Right[i]; Right[i]=aft_XOR_fuc[i]; } ind=0; for(int g=0; g<4; g++){ for(int j=0; j<8; j++){ LeftS[g][j]=Integer.toString(Right[ind]); RightS[g][j]=Integer.toString(aft_XOR_fuc[ind]); ind++; } } arrayprinter.printarray(LeftS,"Left Part"); arrayprinter.printarray(RightS,"Right Part"); } DesPanel.StepsText.append("********After Swap Operation*********"+'\n'); swap32(); contancate(); System.out.println("/nBit Swap :"); for(int i=0;i<64;i++) { System.out.print(Block64[i]); } p.FillInversePermutation();//step1 from 2D to 1D DesPanel.StepsText.append("********* Inverse Permutation Operation in Round *********"+(f+1)+'\n'); p.DoInverseIP(Block64,newBlock64);//step1 -array System.out.println(" "); System.out.println("/nThe Encyption code: "); for(int i=0; i<newBlock64.length; i++){ System.out.print(newBlock64[i]); if(finalEncry==null) finalEncry=Integer.toString(newBlock64[i]); else finalEncry+=Integer.toString(newBlock64[i]); } start=end; end=end+8; index_chooser=0; } System.out.println(""); System.out.println("Final :"+ finalEncry); } public String getEncryption(){ return finalEncry; } public String getDecryption(){ return finalDecry; } public String getBinCi(){ return binCi; } private int ind=0; private String binDec; private String binCi; private static Permutation p; private String keyword; private int index_chooser=0; private String PlainText; private static int index=0; private String cyphir; private static int [] reversedkey=new int[48]; private static String key_reverse ; private static KeyGen key=new KeyGen(); private static int Block64[]=new int[64]; private static int[]num_Left= {1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1}; private static int ch[]=new int[8]; private static int newBlock64[]=new int[64]; private static int [] aft_XOR_fuc=new int[32]; private static String [][] aft_XOR_fucS=new String[4][8]; private static int [] after_SBox=new int[32]; private static int[] C_D=new int[56]; private static int[] XOR_Out=new int[48]; private static int key_in[]=new int[64]; private static int final_key[]=new int[48]; private static int key_out[]=new int[56]; private static int [] Left=new int[32]; private static int[] Right=new int[32]; private static int[] Right_out=new int[48]; private static int[] perm=new int[64]; private static int[] perm_out= new int[64]; private static int newBlock64_[]=new int[64]; private static int C[]=new int[28]; private static int D[]=new int[28]; private byte[][] block=new byte[8][8]; private String [][] blockS= new String[8][8]; private String finalEncry; private String finalDecry; private String Plain_Dec; private String LeftS[][] = new String[4][8]; private String RightS[][] = new String[4][8]; private String XORS[][] = new String[6][8]; private String [][] newBlock64_S = new String[8][8]; } /* * * Please Visit us at www.codemiles.com * * This Program was Developed by www.codemiles.com forums Team * * Please Don't Remove This Comment * */ وهي ملف الـ DesMain /* * * Please Visit us at www.codemiles.com * * This Program was Developed by www.codemiles.com forums Team * * Please Don't Remove This Comment * */ import java.awt.BorderLayout; import java.awt.Container; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.text.AbstractDocument; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.Document; import javax.swing.text.DocumentFilter; /* * DesMain.java * * Created on May 1, 2007, 3:16 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ /** * * @author Mohammed */ public class DesMain { /** Creates a new instance of DesMain */ public DesMain() { } public static void main(String [] rr){ DesPanel mm = new DesPanel(); mm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mm.setVisible(true); } } class DesPanel extends JFrame{ public DesPanel(){ this.setTitle("Des"); this.setSize(800,800); this.setVisible(true); GenerateGUI(); } encrypt en; public static JTextArea StepsText = new JTextArea(10,40); private Container c=this.getContentPane(); private JButton btnCihper = new JButton("Cipher"); private JButton btnDeCihper = new JButton("Decipher"); private JTextArea CipherText = new JTextArea(4,40); private JTextArea OriginalText = new JTextArea(4,40); private JTextArea DeCipherText = new JTextArea(4,40); private JScrollPane OriginalScorl=new JScrollPane(OriginalText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); private JScrollPane CipherScorl=new JScrollPane(CipherText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); private JScrollPane DecipherScorl=new JScrollPane(DeCipherText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); private JScrollPane StepScorl=new JScrollPane(StepsText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); private JTextField KeyWord = new JTextField(16); private JTextField KeyWordTwo = new JTextField(16); private JPanel PanelCipher = new JPanel(); private JPanel PanelDecipher = new JPanel(); private JPanel PanelKeyWord = new JPanel(); private JPanel PanelOriginaltxt = new JPanel(); private JPanel jpstep=new JPanel(); private JLabel lblKeyWord= new JLabel("KeyWord : "); private void GenerateGUI(){ c.setLayout(new GridLayout(4,1)); Document doc = KeyWord.getDocument(); AbstractDocument absDoc = (AbstractDocument )doc; absDoc.setDocumentFilter(new DocumentSizeFilter(8)); KeyWord.setSize(10,1); c.setLayout(new FlowLayout()); PanelKeyWord.setLayout(new FlowLayout()); PanelKeyWord.add(lblKeyWord); PanelKeyWord.add(KeyWord); PanelOriginaltxt.setBorder(BorderFactory.createTitledBorder("Original Text")); PanelOriginaltxt.setLayout(new FlowLayout()); PanelOriginaltxt.add(OriginalScorl); PanelCipher.setBorder(BorderFactory.createTitledBorder("Cipher Text")); PanelCipher.setLayout(new FlowLayout()); PanelCipher.add(CipherScorl); PanelCipher.add(btnCihper); PanelDecipher.setBorder(BorderFactory.createTitledBorder("Decipher Text")); PanelDecipher.setLayout(new FlowLayout()); PanelDecipher.add(DecipherScorl); PanelDecipher.add(btnDeCihper); jpstep.setBorder(BorderFactory.createTitledBorder("Mointor")); jpstep.setLayout(new FlowLayout()); jpstep.add(StepScorl); c.add(PanelKeyWord); c.add(PanelOriginaltxt); c.add(PanelCipher); c.add(PanelDecipher); c.add(jpstep); DoActions(); } private void DoActions(){ ActionHandler action = new ActionHandler(); btnCihper.addActionListener(action); btnDeCihper.addActionListener(action); } private class ActionHandler implements ActionListener{ public void actionPerformed(ActionEvent e) { if(e.getSource()==btnCihper){ String plaintext=OriginalText.getText(); String keyworD=KeyWord.getText(); StepsText.append("keyword : "+keyworD+'\n'); StepsText.append("PlainText : "+plaintext+'\n'); en= new encrypt(plaintext,keyworD); en.DoEncryption(); //OriginalText.append("\n "+ en.getBinCi()); CipherText.append(en.getEncryption()); } if(e.getSource()==btnDeCihper){ en.DoDecryption(); DeCipherText.append("\n "+en.getBinDec()); DeCipherText.setCaretPosition(DeCipherText. getDocument().getLength()); DeCipherText.append("\n"+en.getDecryption()); } } } private String fina; } class DocumentSizeFilter extends DocumentFilter { int maxCharacters; public DocumentSizeFilter(int maxChars) { maxCharacters = maxChars; } public void insertString(FilterBypass fb, int offs, String str, AttributeSet a) throws BadLocationException { if ((fb.getDocument().getLength() + str.length()) <= maxCharacters) super.insertString(fb, offs, str, a); else Toolkit.getDefaultToolkit().beep(); } public void replace(FilterBypass fb, int offs, int length, String str, AttributeSet a) throws BadLocationException { if ((fb.getDocument().getLength() + str.length()- length) <= maxCharacters) super.replace(fb, offs, length, str, a); else Toolkit.getDefaultToolkit().beep(); } } /* * * Please Visit us at www.codemiles.com * * This Program was Developed by www.codemiles.com forums Team * * Please Don't Remove This Comment * */ بتمني منكم تساعدوني ............ وبعتذر منكم لان تأخرت بتزيل الطلب
  6. UDP File Transfer

    :unsure:
  7. UDP File Transfer

    مرحبا , أخي محمود جربت بالأكواد والحمد لله زبطت معي بس الهدف من الاكواد ان ينقل ملف الصورة بس للاسف ما عم ينقل بقى شو بتطلع المشكلة هي الاكواد SERVER import java.io.*; import java.net.*; class Receiver { public static void main(String args[]) throws Exception { //create a datagram socket and bind it with a suitable port DatagramSocket socket = new DatagramSocket(3000); //array of byte used to store received data byte[] receiveData = new byte[128]; System.out.println("Waiting for client file ...\n"); // create an empty datagramPacket to store received data and length DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); socket.receive(receivePacket); String sentence = new String(receivePacket.getData()); FileOutputStream outStream = new FileOutputStream("image.GIF"); } } CLIENT import java.io.*; import java.net.*; class Sender { public static void main(String args []) throws Exception { //create a datagram socket DatagramSocket socket = new DatagramSocket(); //get the IP address of the receiver InetAddress IP = InetAddress.getByName("localhost"); //array of byte to store data FileInputStream fileIn = new FileInputStream("image.GIF"); long fileLen = (new File("image.GIF")).length(); int intFileLen = (int)fileLen; byte[] byteArray = new byte[intFileLen]; fileIn.read(byteArray); fileIn.close(); } }
  8. UDP File Transfer

    السلام عليكم أخي محمود بالنسبة للأخطاء يلي ظهرت بالكود رح حاول فيها بس انت عم تسال ليش استخدمت object هي المس هيك بدها وانا جربت بـ TCP File Transfer وزبط معي ومية المية وهي الاكواد فيك تطلع عليهم و لكن المشكلة عندي بـ UDP File Transfer Server import java.io.*; import java.net.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; public class Reciever { public static void main(String[] args) throws Exception { try { //create a socket with the agreed port Socket link = new Socket("localhost",3000); //create ObjectOutputStream that enable us to buffer array of bytes ObjectInputStream inStream = new ObjectInputStream(link.getInputStream()); //create a array of bytes with the inputStream length (length of recieved array) byte[] byteArray = (byte[])inStream.readObject(); //output stream for writing data to a File FileOutputStream outStream = new FileOutputStream("image.GIF"); //Write byteArray to this file output stream outStream.write(byteArray); //close the connection link.close(); } catch(IOException e) { System.out.println("error..."); } } } Client import java.io.*; import java.net.*; import javax.swing.*; import java.util.Scanner; public class Sender { //declare a ServerSocket private static ServerSocket serverSocket; public static void main(String[] args) { System.out.println("Opening port...\n"); try { //create a ServerSocket with a port number 3000 serverSocket = new ServerSocket(3000); } catch(IOException ioEx) { System.out.println("Unable to attach to port!"); System.exit(1); } try { //create a new socket to connect with client and accept the connection Socket link = serverSocket.accept(); //create ObjectOutputStream that enable us to buffer array of bytes ObjectOutputStream outStream = new ObjectOutputStream(link.getOutputStream()); //creat FileInputStream to obtain input bytes from a file FileInputStream fileIn = new FileInputStream("image.GIF"); //get the file length long fileLen = (new File("image.GIF")).length(); //convert the length to int int intFileLen = (int)fileLen; //create an array of byte with the file length byte[] byteArray = new byte[intFileLen]; //Read bytes of data from this input stream into an array of bytes fileIn.read(byteArray); //close this file input stream fileIn.close(); //write the array of byte to the buffer (ObjectOutputStream) outStream.writeObject(byteArray); } catch(IOException e) { System.out.println("error..."); } } } وبارك الله بك :)
  9. UDP File Transfer

    بارك الله بك اخي الكريم .. عذبتك معي
  10. UDP File Transfer

    السلام عليكم ورحمة الله تعالى وبركاته المطلوب عمل كود لنقل ملف صورة او ملف نص من المرسل للمستقبل اي client to server باستخدام طريقة UDP File Transfer وعملت الكود ولكن للاسف مابينقل الملف بس اعمل run للكود وهي الكود .. receiver import java.io.*; import java.net.*; class Receiver { public static void main(String args[]) throws Exception { //create a datagram socket and bind it with a suitable port DatagramSocket socket = new DatagramSocket(3000); //array of byte used to store received data byte[] receiveData = new byte[128]; System.out.println("Waiting for client file ...\n"); // create an empty datagramPacket to store received data and length DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); socket.receive(receivePacket); String sentence = new String(receivePacket.getData()); FileOutputStream outStream = new FileOutputStream("image.GIF"); } } أما كود الـ client وفيه أخطاء :( import java.io.*; import java.net.*; class Sender { private static Object sendData; private static Object clientSocket; public static void main(String args []) throws Exception { //create a datagram socket DatagramSocket socket = new DatagramSocket(); //get the IP address of the receiver InetAddress IP = InetAddress.getByName("localhost"); //array of byte to store data FileInputStream fileIn = new FileInputStream("image.GIF"); long fileLen = (new File("image.GIF")).length(); int intFileLen = (int)fileLen; byte[] byteArray = new byte[intFileLen]; fileIn.read(byteArray); fileIn.close(); sendData = sentence.getBytes(); //create a datagram packet and give it the requierd parameters DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IP, 3000); //function used to send data socket.send(sendPacket); // close the datagramsocket and terminate the connection clientSocket.close(); } } إذا حد ممكن يقولي وين الخطأ .. بكون ممنونه له كثير
  11. عمل cv

    اي ان شاء الله بكرا او بعد بكرا بالكثير بنزل المطلوب الاول والثاني كله دعواتكم
  12. عمل cv

    السلام عليكم ورحمة الله تعالى وبركاته بتشكرك كثير أخي الشمري وإن شاء الله رح انتبه على هاي الملاحظات وبشوف شو رح يصير معي و اذا زبط بكون الشكر إلك بفضل الله واذا ما زبط معليش رح عذبك معي
  13. [تنبيه - عنوان غير مناسب : ]help me

    عذبتك معي اخي الكريم وكفيت ووفيت والله بس للاسف لما صرت بالبيت كان موعد تسليم الواجب فات زمان يلا لعله خير بس رح حاول لما خلص امتحان لبعد الاحد واعرض الكود عليك وان شاء الله بعرضه وبقلك جربه زابط مية المية وتعلمت منك شي :) الله لا يحرمك من خيره ويعطيك ليرضيك مرة تانية بتأسف عالإزعاج والغلبة
  14. عمل cv

    رغم كل يلي صار هون ,, بتمني ماكون ضايقت حدا وسامحوني وبوعدكم اتعلم وما احتاج لحدا لان كل ظني ان الناس للناس
  15. عمل cv

    اي بعتذر اخي الكريم منكم وآسفة يعني بالك لو انا ما حاولت كان حطيت الاكواد يلي عملتها وبس طلبت منكم تشوفولي المشكلة وين بعتذر مرة تانية منكم اخواني الاعضاااء وخصوصا حضرتك يا استاذ الاحسن ولكن تذكر ان اذا عندك علم هيدا العلم من الله وهبك ياه ولو طلب منك اي حدا سؤال او مساعدة بهيدا العلم واتمسخرت عليه متل هيك ............ الله يلطف فيك