Created
March 11, 2018 04:29
-
-
Save jianminchen/3ee13e2c67acfd65c222cc9b3e77d6dd to your computer and use it in GitHub Desktop.
Encrypt message code review March 10, 2018 8:00 PM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
string decrypt( const string& word ) | |
{ | |
// your code goes here | |
string source(word.length(),' '); | |
int i = 0; | |
int prefixSum = 0; | |
for(char c : word){ | |
source[i] = word[i] - 1 - prefixSum; | |
prefixSum += source[i]; | |
while(source[i] <'a' || source[i] > 'z') | |
source[i] += 26; | |
i++; | |
} | |
return source; | |
} | |
int main() { | |
return 0; | |
} | |
/* | |
a b c d e f g h i j k l m n o p q r s t u v w x y z | |
d n o t q | |
c | |
source[0] = encrypt[0] - 1 | |
source[1] = (encrypt[1] - 1 - source[0]) >=a && <= z | |
while(source[i] >= a && <=z) | |
source[i] += 26 | |
114 + 100 -> 214 -> 26 * n -> a - z | |
step 2 number it is sum of series of original chars: | |
99 + 1 | |
99 + 1 + 114 | |
... | |
encrypt[i] = 1 + source[0] + source[1] +...+ source[i] - 26 * ni -> a - z | |
algebra equation on line 29 -> source[i] -> right hand size, move other terms to left side | |
source[i] -> induction | |
encrypt[i] - 1 - source[0] - ... - source[i - 1] + 26 * ni -> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment