Created
January 23, 2017 19:31
-
-
Save naitsric/0c1b86e33f505052c58bce17914455c5 to your computer and use it in GitHub Desktop.
test, encrypt and decrypt
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
import math | |
def encrypt(text): | |
total_sum = 0 | |
total_cnt = 0 | |
for c in text: | |
total_cnt += 1 | |
total_sum += ord(c) ** total_cnt | |
print(total_sum) | |
return total_cnt, total_sum | |
def decrypt(total_cnt, total_sum): | |
cnt = total_cnt | |
text = [] | |
total_subs = total_sum | |
while cnt != 0: | |
c = math.pow(total_subs, 1 / cnt) | |
text.append(chr(int(c))) | |
total_subs -= int(c) ** cnt | |
cnt -= 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment