encryption - Java Cryptography Affine cipher wrong output -
i trying affine methods output totally wrong , have no clue how fix it, can @ , tell me wrong
public void affine(int a, int b){ stringbuilder builder = new stringbuilder(); int len = jmesaj.gettext().length(); //length of input (int = 0; < len; i++){ char currentchar = jmesaj.gettext().charat(i); char finalchar = ((char)(currentchar +(a*i + b)% 26)); builder.append(finalchar); } string result = builder.tostring(); builder.delete( 0 , builder.length() -1 ); jencryptionresult.settext(result); //display result in jtextarea }
it seems me assuming 'a' = 1, 'b' = 2, etc. also, affine algorithm different. if you're using 26 module makes me thing cyphering 'a' 'z'. if that's true try adding offset in line, this:
char finalchar = (char)((a*(currentchar - 'a') + b) % 26 + 'a');
Comments
Post a Comment