fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.math.BigInteger;
  4.  
  5. class YatinRSA{
  6. public static void main(String[] args) {
  7. System.out.println("Testing Yatin's RSA..\n");
  8.  
  9. int p = 5;
  10. int q = 17;
  11. int n = 85; // p * q - modulus
  12.  
  13. int lcm = 16; // (lcm(p-1,q-1))
  14. int e = 3; // coprime to lcm - exponent
  15.  
  16. int d = 11; // de % n = 1 - privatekey
  17.  
  18. for (int i = 1; i < 101; i++) {
  19. algorithm(n,e,d,i);
  20. }
  21. }
  22.  
  23. static void algorithm(int modulus, int exponent, int privatekey, int input) {
  24. BigInteger bigModulus = BigInteger.valueOf(modulus);
  25.  
  26. BigInteger encrytion =
  27. BigInteger.valueOf(input)
  28. .modPow(BigInteger.valueOf(exponent),
  29. bigModulus);
  30.  
  31. BigInteger decyption =
  32. encrytion.modPow(BigInteger.valueOf(privatekey),
  33. bigModulus);
  34.  
  35. System.out.printf("Value: %3s\tEncypted: %3s\tDecypts? %s\n",
  36. input,
  37. encrytion,
  38. input == decyption.intValue());
  39. }
  40.  
  41. }
  42.  
Success #stdin #stdout 0.18s 35824KB
stdin
 
stdout
Testing Yatin's RSA..

Value:   1	Encypted:   1	Decypts? true
Value:   2	Encypted:   8	Decypts? true
Value:   3	Encypted:  27	Decypts? true
Value:   4	Encypted:  64	Decypts? true
Value:   5	Encypted:  40	Decypts? true
Value:   6	Encypted:  46	Decypts? true
Value:   7	Encypted:   3	Decypts? true
Value:   8	Encypted:   2	Decypts? true
Value:   9	Encypted:  49	Decypts? true
Value:  10	Encypted:  65	Decypts? true
Value:  11	Encypted:  56	Decypts? true
Value:  12	Encypted:  28	Decypts? true
Value:  13	Encypted:  72	Decypts? true
Value:  14	Encypted:  24	Decypts? true
Value:  15	Encypted:  60	Decypts? true
Value:  16	Encypted:  16	Decypts? true
Value:  17	Encypted:  68	Decypts? true
Value:  18	Encypted:  52	Decypts? true
Value:  19	Encypted:  59	Decypts? true
Value:  20	Encypted:  10	Decypts? true
Value:  21	Encypted:  81	Decypts? true
Value:  22	Encypted:  23	Decypts? true
Value:  23	Encypted:  12	Decypts? true
Value:  24	Encypted:  54	Decypts? true
Value:  25	Encypted:  70	Decypts? true
Value:  26	Encypted:  66	Decypts? true
Value:  27	Encypted:  48	Decypts? true
Value:  28	Encypted:  22	Decypts? true
Value:  29	Encypted:  79	Decypts? true
Value:  30	Encypted:  55	Decypts? true
Value:  31	Encypted:  41	Decypts? true
Value:  32	Encypted:  43	Decypts? true
Value:  33	Encypted:  67	Decypts? true
Value:  34	Encypted:  34	Decypts? true
Value:  35	Encypted:  35	Decypts? true
Value:  36	Encypted:  76	Decypts? true
Value:  37	Encypted:  78	Decypts? true
Value:  38	Encypted:  47	Decypts? true
Value:  39	Encypted:  74	Decypts? true
Value:  40	Encypted:  80	Decypts? true
Value:  41	Encypted:  71	Decypts? true
Value:  42	Encypted:  53	Decypts? true
Value:  43	Encypted:  32	Decypts? true
Value:  44	Encypted:  14	Decypts? true
Value:  45	Encypted:   5	Decypts? true
Value:  46	Encypted:  11	Decypts? true
Value:  47	Encypted:  38	Decypts? true
Value:  48	Encypted:   7	Decypts? true
Value:  49	Encypted:   9	Decypts? true
Value:  50	Encypted:  50	Decypts? true
Value:  51	Encypted:  51	Decypts? true
Value:  52	Encypted:  18	Decypts? true
Value:  53	Encypted:  42	Decypts? true
Value:  54	Encypted:  44	Decypts? true
Value:  55	Encypted:  30	Decypts? true
Value:  56	Encypted:   6	Decypts? true
Value:  57	Encypted:  63	Decypts? true
Value:  58	Encypted:  37	Decypts? true
Value:  59	Encypted:  19	Decypts? true
Value:  60	Encypted:  15	Decypts? true
Value:  61	Encypted:  31	Decypts? true
Value:  62	Encypted:  73	Decypts? true
Value:  63	Encypted:  62	Decypts? true
Value:  64	Encypted:   4	Decypts? true
Value:  65	Encypted:  75	Decypts? true
Value:  66	Encypted:  26	Decypts? true
Value:  67	Encypted:  33	Decypts? true
Value:  68	Encypted:  17	Decypts? true
Value:  69	Encypted:  69	Decypts? true
Value:  70	Encypted:  25	Decypts? true
Value:  71	Encypted:  61	Decypts? true
Value:  72	Encypted:  13	Decypts? true
Value:  73	Encypted:  57	Decypts? true
Value:  74	Encypted:  29	Decypts? true
Value:  75	Encypted:  20	Decypts? true
Value:  76	Encypted:  36	Decypts? true
Value:  77	Encypted:  83	Decypts? true
Value:  78	Encypted:  82	Decypts? true
Value:  79	Encypted:  39	Decypts? true
Value:  80	Encypted:  45	Decypts? true
Value:  81	Encypted:  21	Decypts? true
Value:  82	Encypted:  58	Decypts? true
Value:  83	Encypted:  77	Decypts? true
Value:  84	Encypted:  84	Decypts? true
Value:  85	Encypted:   0	Decypts? false
Value:  86	Encypted:   1	Decypts? false
Value:  87	Encypted:   8	Decypts? false
Value:  88	Encypted:  27	Decypts? false
Value:  89	Encypted:  64	Decypts? false
Value:  90	Encypted:  40	Decypts? false
Value:  91	Encypted:  46	Decypts? false
Value:  92	Encypted:   3	Decypts? false
Value:  93	Encypted:   2	Decypts? false
Value:  94	Encypted:  49	Decypts? false
Value:  95	Encypted:  65	Decypts? false
Value:  96	Encypted:  56	Decypts? false
Value:  97	Encypted:  28	Decypts? false
Value:  98	Encypted:  72	Decypts? false
Value:  99	Encypted:  24	Decypts? false
Value: 100	Encypted:  60	Decypts? false