Skip to content

Commit 47a9ea2

Browse files
authored
Simplify code by dropping support for legacy Python (#1143)
* Simplify code by dropping support for legacy Python * sort() --> sorted()
1 parent 32aa7ff commit 47a9ea2

File tree

145 files changed

+367
-976
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+367
-976
lines changed

CONTRIBUTING.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ We want your work to be readable by others; therefore, we encourage you to note
5656

5757
```python
5858
"""
59-
This function sums a and b
59+
This function sums a and b
6060
"""
6161
def sum(a, b):
6262
return a + b
@@ -82,13 +82,13 @@ We want your work to be readable by others; therefore, we encourage you to note
8282
The following "testing" approaches are **not** encouraged:
8383

8484
```python
85-
input('Enter your input:')
85+
input('Enter your input:')
8686
# Or even worse...
87-
input = eval(raw_input("Enter your input: "))
87+
input = eval(input("Enter your input: "))
8888
```
89-
89+
9090
However, if your code uses __input()__ then we encourage you to gracefully deal with leading and trailing whitespace in user input by adding __.strip()__ to the end as in:
91-
91+
9292
```python
9393
starting_value = int(input("Please enter a starting value: ").strip())
9494
```
@@ -99,13 +99,13 @@ We want your work to be readable by others; therefore, we encourage you to note
9999
def sumab(a, b):
100100
return a + b
101101
# Write tests this way:
102-
print(sumab(1,2)) # 1+2 = 3
103-
print(sumab(6,4)) # 6+4 = 10
102+
print(sumab(1, 2)) # 1+2 = 3
103+
print(sumab(6, 4)) # 6+4 = 10
104104
# Or this way:
105-
print("1 + 2 = ", sumab(1,2)) # 1+2 = 3
106-
print("6 + 4 = ", sumab(6,4)) # 6+4 = 10
105+
print("1 + 2 = ", sumab(1, 2)) # 1+2 = 3
106+
print("6 + 4 = ", sumab(6, 4)) # 6+4 = 10
107107
```
108-
108+
109109
Better yet, if you know how to write [__doctests__](https://docs.python.org/3/library/doctest.html), please consider adding them.
110110

111111
- Avoid importing external libraries for basic algorithms. Only use those libraries for complicated algorithms.

ciphers/affine_cipher.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
import sys, random, cryptomath_module as cryptoMath
32

43
SYMBOLS = r""" !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"""

ciphers/atbash.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1-
try: # Python 2
2-
raw_input
3-
unichr
4-
except NameError: # Python 3
5-
raw_input = input
6-
unichr = chr
7-
8-
9-
def Atbash():
1+
def atbash():
102
output=""
11-
for i in raw_input("Enter the sentence to be encrypted ").strip():
3+
for i in input("Enter the sentence to be encrypted ").strip():
124
extract = ord(i)
135
if 65 <= extract <= 90:
14-
output += unichr(155-extract)
6+
output += chr(155-extract)
157
elif 97 <= extract <= 122:
16-
output += unichr(219-extract)
8+
output += chr(219-extract)
179
else:
18-
output+=i
10+
output += i
1911
print(output)
2012

2113

2214
if __name__ == '__main__':
23-
Atbash()
15+
atbash()

ciphers/brute_force_caesar_cipher.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
def decrypt(message):
32
"""
43
>>> decrypt('TMDETUX PMDVU')

ciphers/onepad_cipher.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import print_function
2-
31
import random
42

53

@@ -15,7 +13,7 @@ def encrypt(self, text):
1513
cipher.append(c)
1614
key.append(k)
1715
return cipher, key
18-
16+
1917
def decrypt(self, cipher, key):
2018
'''Function to decrypt text using psedo-random numbers.'''
2119
plain = []

ciphers/rabin_miller.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
# Primality Testing with the Rabin-Miller Algorithm
32

43
import random

ciphers/rot13.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
def dencrypt(s, n):
32
out = ''
43
for c in s:

ciphers/rsa_cipher.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
import sys, rsa_key_generator as rkg, os
32

43
DEFAULT_BLOCK_SIZE = 128
@@ -16,7 +15,7 @@ def main():
1615
if mode == 'encrypt':
1716
if not os.path.exists('rsa_pubkey.txt'):
1817
rkg.makeKeyFiles('rsa', 1024)
19-
18+
2019
message = input('\nEnter message: ')
2120
pubKeyFilename = 'rsa_pubkey.txt'
2221
print('Encrypting and writing to %s...' % (filename))

ciphers/rsa_key_generator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
import random, sys, os
32
import rabin_miller as rabinMiller, cryptomath_module as cryptoMath
43

ciphers/simple_substitution_cipher.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
import sys, random
32

43
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@@ -18,7 +17,7 @@ def main():
1817
translated = decryptMessage(key, message)
1918

2019
print('\n%sion: \n%s' % (mode.title(), translated))
21-
20+
2221
def checkValidKey(key):
2322
keyList = list(key)
2423
lettersList = list(LETTERS)
@@ -49,7 +48,7 @@ def translateMessage(key, message, mode):
4948

5049
if mode == 'decrypt':
5150
charsA, charsB = charsB, charsA
52-
51+
5352
for symbol in message:
5453
if symbol.upper() in charsA:
5554
symIndex = charsA.find(symbol.upper())

0 commit comments

Comments
 (0)