Skip to content

Instantly share code, notes, and snippets.

@M-ZubairAhmed
Created March 22, 2017 04:33
Show Gist options
  • Save M-ZubairAhmed/626dc070351f7412a7dc72e5ca63281f to your computer and use it in GitHub Desktop.
Save M-ZubairAhmed/626dc070351f7412a7dc72e5ca63281f to your computer and use it in GitHub Desktop.
Algorithm for decrypting improved version of Caesar cypher
public static String demovingShift(String inputCodedString, int shift, int decremental){
char[] inCodedCharArr = new char[inputCodedString.length()];
for (int q = 0; q < inputCodedString.length(); q++) {
int DeFlushV =0 , DeFlushVDec = 0;
DeFlushV = (int)inputCodedString.charAt(q);
if (DeFlushV >= 65 && DeFlushV <=90){
DeFlushVDec = DeFlushV - shift;
if(DeFlushVDec < 65) {
while (DeFlushVDec < 65) {
DeFlushVDec = 91 - (65 - DeFlushVDec);
}
inCodedCharArr[q] = (char) DeFlushVDec;
}
else {
inCodedCharArr[q] = (char)DeFlushVDec;}}
else if (DeFlushV >= 97 && DeFlushV <=122){
DeFlushVDec = DeFlushV - shift;
if(DeFlushVDec < 97) {
while (DeFlushVDec < 97) {
DeFlushVDec = 123 - (97 - DeFlushVDec);
}
inCodedCharArr[q] = (char) DeFlushVDec;
}
else {
inCodedCharArr[q] = (char)DeFlushVDec;}}
else {
inCodedCharArr[q] = inputCodedString.charAt(q);}
shift +=decremental;
}
String decodedString = new String(inCodedCharArr);
return decodedString;
}
@M-ZubairAhmed
Copy link
Author

Decryption of Caesar Improved Cipher with Incremental key

Algorithm decodes the coded text message back to original on the following conditions:

  • Initial key is known
  • Decremental key is available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment