-
Notifications
You must be signed in to change notification settings - Fork 0
/
crypter.py
97 lines (53 loc) · 1.58 KB
/
crypter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#-------------------------------------------------------------------------------
# Name: sikessem-encryption
# Purpose:
#
# Author: SIGUI Kessé Emmanuel
#
# Created: 18/02/2021
# Copyright: (c) SIKessEm 2021
# Licence: MIT
#-------------------------------------------------------------------------------
import string
letters = string.ascii_letters
letters = list(letters)
lenght = len(letters)
def encrypt(word, step):
code = ''
word_letters = list(word)
for word_letter in word_letters:
if word_letter == ' ':
code += word_letter
continue
index = None
for letter in letters:
if letter == word_letter:
index = letters.index(letter)
break
if index is None:
index = word_letters.index(word_letter)
position = index + step
rest = lenght - position
if rest < 0:
position = rest + step - 1
code += letters[position]
return code
def decrypt(word, step):
code = ''
word_letters = list(word)
for word_letter in word_letters:
if word_letter == ' ':
code += word_letter
continue
index = 0
for letter in letters:
if letter == word_letter:
index = letters.index(letter)
break
if index is None:
index = word_letters.index(word_letter)
position = index - step
if position < 0:
position += lenght
code += letters[position]
return code