33import random
44import string
55
6+
67def random_chars () -> str :
7- '''
8+ """
89 Adds random 3 charaters to the string.
9-
10- '''
11- return '' .join (random .choices (string .ascii_letters , k = 3 ))
10+
11+ """
12+ return "" .join (random .choices (string .ascii_letters , k = 3 ))
13+
1214
1315def random_digits () -> str :
14- '''
16+ """
1517 Adds 3 random digits to the string.
16- '''
17-
18- return '' .join (random .choices (string .digits , k = 3 ))
18+ """
19+
20+ return "" .join (random .choices (string .digits , k = 3 ))
1921
22+
23+ < << << << HEAD
2024def encode (code : str ) -> str :
2125 '''
26+ =======
27+ def encode(code) -> str:
28+ """
29+ >>>>>>> cb237ed2095a60e62d73afd8b17c1207cc1fb4f9
2230 Encodes the code by shifting the first character to the end of the original string,
2331 and adding the 3 random_characters + 3 random-digits + original string(code) + 3 random-digits + 3 random_characters.
24- unless the length of the code exceeds 3 or equals to it.'''
25-
32+ unless the length of the code exceeds 3 or equals to it."""
33+
2634 if len(code) >= 3:
2735 code = code[1:] + code[0]
28- code = random_chars () + random_digits () + code + random_digits () + random_chars ()
36+ code = (
37+ random_chars() + random_digits() + code + random_digits() + random_chars()
38+ )
2939 else:
3040 code = code[::-1]
31- code = random_chars () + random_digits () + code + random_digits () + random_chars ()
41+ code = (
42+ random_chars() + random_digits() + code + random_digits() + random_chars()
43+ )
3244 return code
3345
46+ <<<<<<< HEAD
3447def decode(code: str) -> str:
3548 '''
49+ == == == =
50+
51+ def decode (code ) -> str :
52+ """
53+ >>>>>>> cb237ed2095a60e62d73afd8b17c1207cc1fb4f9
3654 decodes the encoded string by removing the randomly added characters and reversing the shift
37-
38- '''
39-
55+
56+ """
57+
4058 code = code [6 :- 6 ]
4159 if len (code ) >= 3 :
4260 code = code [- 1 ] + code [:- 1 ]
4361 else :
4462 code = code [::- 1 ]
4563 return code
4664
65+
4766if __name__ == "__main__" :
4867 code = input ("Enter the code: " )
4968 encoded = encode (code )
50- decoded = decode (encoded )
69+ decoded = decode (encoded )
5170 print (f"Original → { code } " )
5271 print (f"Encoded → { encoded } " )
53- print (f"Decoded → { decoded } " )
72+ print (f"Decoded → { decoded } " )
0 commit comments