Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1b30337

Browse files
fixed indexing error (#23)
Enter your message: vishal Enter you key [1 - 26]: 7 Encrypt or Decrypt? [E/D]: e --------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-9-9d857a810c45> in <module> 35 36 if __name__ == '__main__': ---> 37 main() <ipython-input-9-9d857a810c45> in main() 30 31 if choice.lower().startswith('e'): ---> 32 print(encrypt(message, key)) 33 else: 34 print(decrypt(message, key)) <ipython-input-9-9d857a810c45> in encrypt(message, key) 9 num = LETTERS.find(chars) 10 num += key ---> 11 encrypted += LETTERS[num] 12 13 return encrypted IndexError: string index out of range ______________________________________________ Above issue was solved
1 parent e0eb3f7 commit 1b30337

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

‎Programs/P40_CipherText.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ def encrypt(message, key):
1111
if chars in LETTERS:
1212
num = LETTERS.find(chars)
1313
num += key
14-
encrypted += LETTERS[num]
14+
if num>25:
15+
num=num%25
16+
num=num-1
17+
encrypted =encrypted + LETTERS[num]
1518

1619
return encrypted
1720

@@ -21,8 +24,11 @@ def decrypt(message, key):
2124
for chars in message:
2225
if chars in LETTERS:
2326
num = LETTERS.find(chars)
24-
num -= key
25-
decrypted += LETTERS[num]
27+
if num>25:
28+
num=num%25
29+
num=num-1
30+
num = num -key
31+
decrypted =decrypted+LETTERS[num]
2632

2733
return decrypted
2834

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /