java - Difference between these two "methods" for simple character encryption -
i have trouble understanding simple method encrypting characters in string. here's method:
encryptedchar = (char) (’a’ + (originalchar -’a’ + offset) % 26);
i don't understand need 'a' - 'a'
since cancel out. reason behind it?
why shouldn't use following method?
encryptedchar = (char) ((originalchar + offset) % 26);
shouldn't work same?
encryptedchar = (char) ('a' + (originalchar -'a' + offset) % 26);
the 2 'a' don't cancel each other, since second 1 inside expression operand of modulus operator.
'a' + (originalchar -'a' + offset) % 26
- here each letter mapped different letter.((originalchar + offset) % 26)
- here each letter mapped character int value between 0 , 25.
Comments
Post a Comment