File tree 1 file changed +18
-6
lines changed
1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change 1
- def dencrypt (s , n ):
1
+ def dencrypt (s : str , n : int = 13 ):
2
+ """
3
+ https://en.wikipedia.org/wiki/ROT13
4
+
5
+ >>> msg = "My secret bank account number is 173-52946 so don't tell anyone!!"
6
+ >>> s = dencrypt(msg)
7
+ >>> s
8
+ "Zl frperg onax nppbhag ahzore vf 173-52946 fb qba'g gryy nalbar!!"
9
+ >>> dencrypt(s) == msg
10
+ True
11
+ """
2
12
out = ""
3
13
for c in s :
4
- if c >= "A" and c <= "Z" :
14
+ if "A" <= c <= "Z" :
5
15
out += chr (ord ("A" ) + (ord (c ) - ord ("A" ) + n ) % 26 )
6
- elif c >= "a" and c <= "z" :
16
+ elif "a" <= c <= "z" :
7
17
out += chr (ord ("a" ) + (ord (c ) - ord ("a" ) + n ) % 26 )
8
18
else :
9
19
out += c
10
20
return out
11
21
12
22
13
23
def main ():
14
- s0 = "HELLO"
24
+ s0 = input ( "Enter message: " )
15
25
16
26
s1 = dencrypt (s0 , 13 )
17
- print (s1 ) # URYYB
27
+ print ("Encryption:" , s1 )
18
28
19
29
s2 = dencrypt (s1 , 13 )
20
- print (s2 ) # HELLO
30
+ print ("Decryption: " , s2 )
21
31
22
32
23
33
if __name__ == "__main__" :
34
+ import doctest
35
+ doctest .testmod ()
24
36
main ()
You can’t perform that action at this time.
0 commit comments