9 static final String pass
= "the traveller in the grey riding-coat, who called himself mr. melville, was contemplating the malice of which the gods are capable.";
11 public static void main(String
[] args
)
14 System
.out
.println("\n PART 2 ");
25 final int alpha
= 5, beta
= 11;
27 System
.out
.printf("newcode %d %d %n", newcode
[0], newcode
[1]);
29 for (int i
= 0; i
< pass
.length(); i
++)
31 char nextCh
= pass
.charAt(i
);
33 if (nextCh
>= 'a' && nextCh
<= 'z')
35 newcode
[0] = wrap2(newcode
[0] + alpha
* newcode
[1]);
36 newcode
[1] = wrap2(newcode
[1] + beta
* ci(nextCh
));
38 System
.out
.printf("nextchar %c newcode %c %c %n", nextCh
, ic(newcode
[0]), ic(newcode
[1]));
39 } //else skip this char
46 //assuming string length > 1
49 ci(pass
.charAt(0)), ci(pass
.charAt(1))
52 System
.out
.printf("oldcode %d %d %n", oldcode
[0], oldcode
[1]);
54 for (int i
= 2; i
< pass
.length(); i
++)
56 char nextCh
= pass
.charAt(i
);
58 if (nextCh
>= 'a' && nextCh
<= 'z')
60 //System.out.printf(" next char %c %d %n", nextCh, ci(nextCh));
61 oldcode
[0] = wrap(oldcode
[0] + oldcode
[1]);
62 oldcode
[1] = wrap(oldcode
[1] + ci(nextCh
));
64 System
.out
.printf("next char %c oldcode %c %c %n", nextCh
, ic(oldcode
[0]), ic(oldcode
[1]));
65 } //else skip this char
70 //char conversion to int scale, 1-based
76 //for readability, the int in char form
79 return (char) (x
+ 'a' - 1);
82 //oldwrap only needed adjustment by 26
83 static int wrap(int x
)
93 //new wrap needs a modulus
94 static int wrap2(int x
)
98 return (x
- 1) % 26 + 1;