Decryption function
- Points: 9
Description
You are provided with the following encryption function:
f(x)=21x+11 [26]
First, you have to encrypt the word
Then, your mission is to find the decryption functiong
.
Finally, you have to decrypt the wordGELKT
.
Details
- [26] means “modulo 26”.
- The decryption function will be of the following form:
g(y)=ay+b[26]
, witha
andb
natural integers lower than 26, andy=f(x)
. - You will enter the answer lowercase in the form
1
(crypted word)_(decryption function)_(decrypted word)
Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import string
alphabet = string.ascii_lowercase
def f(x: int) -> int:
return (21 * x + 11) % 26
def f_inv(y: int) -> int:
# y = 21 * x + 11
# --> 21 * x = y - 11
# --> 5 * 21 * x = 5 * (y - 11)
# --> 1 * x = 5 * y - 3
# --> x = 5 * y + 23
return (5 * y + 23) % 26
def encrypt(str):
return "".join(alphabet[f(alphabet.find(c))] for c in str)
def decrypt(str):
return "".join(alphabet[f_inv(alphabet.find(c))] for c in str)
print(encrypt("google"))
print("----")
print(decrypt("gelkt"))
The flag is
1
W3C{httir_5y+23[26]_bravo}
This post is licensed under CC BY 4.0 by the author.