Skip to content

Commit 39a388e

Browse files
committed
By Zhao Kun Peng
1 parent 721c128 commit 39a388e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

checkio/to_encrypt.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def to_encrypt(text, delta):
2+
s=''
3+
for i in text:
4+
if ord(i)== 32:
5+
s+= chr(32)
6+
elif ord(i) + delta > 122:
7+
s = s + chr(ord('a')+ord(i)+delta-ord('z')-1)
8+
elif ord(i) + delta < 97:
9+
s = s + chr(ord('z')-ord('a')+ord(i)+delta +1 )
10+
else:
11+
s = s +chr(ord(i)+delta)
12+
return s
13+
if __name__ == '__main__':
14+
print("Example:")
15+
print(to_encrypt('abc', 10))
16+
17+
#These "asserts" using only for self-checking and not necessary for auto-testing
18+
assert to_encrypt("a b c", 3) == "d e f"
19+
assert to_encrypt("a b c", -3) == "x y z"
20+
assert to_encrypt("simple text", 16) == "iycfbu junj"
21+
assert to_encrypt("important text", 10) == "swzybdkxd dohd"
22+
assert to_encrypt("state secret", -13) == "fgngr frperg"
23+
print("Coding complete? Click 'Check' to earn cool rewards!")

0 commit comments

Comments
 (0)