Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created January 8, 2018 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/c6576510820102e03eff5d31276b9290 to your computer and use it in GitHub Desktop.
Save jianminchen/c6576510820102e03eff5d31276b9290 to your computer and use it in GitHub Desktop.
decrypt message -
#include <iostream>
#include <string>
using namespace std;
/*
z .....
122
123
97
encryption
r -> n
114
114 + 100 = 214
214 - n * 26 = range a - z , a - 97 - 97 + 26
114 + 100 - n * 26 = 110
?
y + 100 - n * 26 = 110
?
? sum of source arr[i] + 1
y = 110 - item2No + n * 26 -> a - z
110 - 100 = 10 + 26 * 4 = 114;
111 - (114 + 100) = -103 + 8 * 26 = 105;
step 2
step 1 ->
99 114 105 109 101
100 1 + 99 +114 1 + 99 + 114 + 105
how to solve the value y?
decrption:
n -> r
110 -> 114
(char)(x)
(int)c
97 + 'c' - 'a'
*/
string decrypt( const string& word )
{
// your code goes here
int n = (int)word.size();
if (n < 1)
return "";
int itemTwoNum = (int)word[0];
string result;
result += (char)(itemTwoNum - 1);
for (int i = 1; i < n; i++) {
int diff = (int)word[i] - itemTwoNum;
while (diff < 97) {
diff += 26;
}
result += (char)diff;
itemTwoNum += diff;
}
return result;
}
int main() {
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment