code_junkie

How can I translate printf(“%c”,M); from C to Java for my DES implementation

Nov 13th, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. printf("%c",M);
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class DES {
  6.  
  7. /**
  8. * @param args
  9. */
  10. public static void main(String[] args) {
  11.  
  12. Scanner eingabe = new Scanner(System.in);
  13.  
  14. int p, q, key2, fn, encryption_key, temp1 , temp2 ,
  15. t, s =0 , privatekey1=1, b=0 , passwort_s=0, klartext;
  16. int[] Cipher = new int [100];
  17. String passwort;
  18.  
  19. System.out.println("Enter the value of p and q");
  20.  
  21. p = eingabe.nextInt();
  22. q = eingabe.nextInt();
  23.  
  24. System.out.println(p);
  25. System.out.println(q);
  26.  
  27. key2= p*q;
  28.  
  29.  
  30. fn=(p-1)*(q-1);
  31. System.out.println("Enter Enryption key e: ");
  32. encryption_key = eingabe.nextInt();
  33.  
  34. do {
  35.  
  36. s=(privatekey1*encryption_key)%fn;
  37. privatekey1++;
  38.  
  39. } while (s!=1);
  40.  
  41. privatekey1=privatekey1-1;
  42.  
  43.  
  44.  
  45. System.out.println("Public Key : "+ encryption_key + ","+ key2 );
  46. System.out.println("Private Key: "+ privatekey1 + "," +key2 );
  47. System.out.println("Enter Message: ");
  48. passwort= eingabe.next();
  49. for ( temp2 = 0; temp2 < passwort.length(); temp2++)
  50. {
  51. t = passwort.charAt(temp2);
  52. passwort_s=1;
  53. for(temp1 =0 ; temp1< encryption_key ; temp1++){
  54. passwort_s= passwort_s*t%key2;
  55. }
  56. passwort_s= passwort_s%key2;
  57. System.out.println(passwort_s);
  58. }
  59.  
  60. System.out.println("Enter cipher Text: ");
  61. for(temp1=0;temp1< passwort.length(); temp1++ )
  62. {
  63. Cipher[temp1]= eingabe.nextInt();
  64. }
  65.  
  66. System.out.println("Plainttext: ");
  67. for(temp2 =0; temp2 < passwort.length(); temp2++);
  68. {
  69. klartext=1;
  70.  
  71. for(temp1 =0; temp1 < privatekey1; temp1 ++){
  72. klartext=klartext*Cipher[temp2]%key2;
  73. }
  74. klartext=klartext%key2;
  75. System.out.println(klartext);
  76. }
  77. }
  78. }
  79.  
  80. printf("%c",M);
  81.  
  82. int a = 70;
  83. char c = (char)a;
  84. System.out.print(a);
  85.  
  86. output.print((char)M);
Add Comment
Please, Sign In to add comment