ceasar_cipher   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 3

2 Functions

Rating   Name   Duplication   Size   Complexity  
A shift_char() 0 3 1
A to_encrypt() 0 3 2
1
def shift_char(char, delta):
2
    base_ord = ord('a')
3
    return chr(base_ord + (ord(char) - base_ord + delta) % 26)
4
5
6
def to_encrypt(text, delta):
7
    char_list = [shift_char(i, delta) if 'a' <= i <= 'z' else i for i in text]
8
    return ''.join(char_list)
9
10
11
if __name__ == '__main__':
12
    print("Example:")
13
    print(to_encrypt('abc', 10))
14
15
    # These "asserts" using only for self-checking
16
    # and not necessary for auto-testing
17
    assert to_encrypt("a b c", 3) == "d e f"
18
    assert to_encrypt("a b c", -3) == "x y z"
19
    assert to_encrypt("simple text", 16) == "iycfbu junj"
20
    assert to_encrypt("important text", 10) == "swzybdkxd dohd"
21
    assert to_encrypt("state secret", -13) == "fgngr frperg"
22
    print("Coding complete? Click 'Check' to earn cool rewards!")
23