Commit Graph

144 Commits

Author SHA1 Message Date
Du Yuanchao
4d0a8f2355
Optimized recursive_bubble_sort (#2410)
* optimized recursive_bubble_sort

* Fixed doctest error due whitespace

* reduce loop times for optimization

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-09-10 10:31:26 +02:00
TrapinchO
30126c26dd
Added enigma machine emulator (#2345)
* Added Enigma machine file

Added Enigma machine file to 'ciphers' section

* Added doctest to validator

* Fixed typo

* Shortened some lines

* Shortened some lines

* Update enigma_machine.py

* Shortened some lines

* Update enigma_machine.py

* Update enigma_machine.py

* Update enigma_machine2.py

* Update enigma_machine2.py

* added f-strings

* Update enigma_machine2.py

* Update enigma_machine2.py

* Updated some numbers

* Plugboard improvement

Added option to separate pair for plugboard by spaces

* renamed variable

* renamed some variables

* improved plugboard exception

* Update enigma_machine2.py

* Update enigma_machine2.py
2020-08-26 21:52:17 +02:00
Christian Clauss
5f4da5d616
isort --profile black . (#2181)
* updating DIRECTORY.md

* isort --profile black .

* Black after

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-07-06 09:44:19 +02:00
vinayak
2d3d660155
black fixes and Travis CI fixes (#2160)
* black format

* updating DIRECTORY.md

* fixes

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-07-02 20:02:15 +05:30
Christian Clauss
9316e7c014
Set the Python file maximum line length to 88 characters (#2122)
* flake8 --max-line-length=88

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-06-16 10:09:19 +02:00
Christian Clauss
1f8a21d727
Tighten up psf/black and flake8 (#2024)
* Tighten up psf/black and flake8

* Fix some tests

* Fix some E741

* Fix some E741

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-05-22 08:10:11 +02:00
mateuszz0000
965d02ad41
Update atbash cipher (doc, doctest, performance) (#2017)
* Update atbash

* Add benchmark() to quantify the performance improvement

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-05-20 08:23:17 +02:00
Christian Clauss
38d2e98665
hill_cipher.py: gcd() -> greatest_common_divisor() (#1997)
* hill_cipher.py: gcd() -> greatest_common_divisor()

* fixup! Format Python code with psf/black push

* import string

* updating DIRECTORY.md

* Change matrix to array

Add more tests

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: John Law <johnlaw.po@gmail.com>
2020-05-18 13:05:51 +02:00
Bharath kumar Reddy Kotha
aa120cea12
Add tests and type hints to hill cipher (#1991)
* Added tests and type hints to hill cipher

* Remove extra >>>

* import doctest

Co-authored-by: John Law <johnlaw.po@gmail.com>
2020-05-18 09:03:20 +02:00
Maxim R
369562a1e8
Upgrades to caesar_cipher.py (#1958)
* Added more flexibility to functions, decreased amount of repeating code

* Added docstrings

* Updated input functions

* Added doctests

* removed test piece of code

* black .

* Updated caesar cipher standard alphabet to fit python 3.8

* Update and rename sleepsort.py to sleep_sort.py

* Or 4

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-05-08 07:44:07 +02:00
Maxim R
4acc28ba55
Added new algorithm: cracking caesar cipher with the chi-squared test (#1950)
* added decrypt_caesar_with_chi_squared.py and ran all checks

* Updated default parameters

Removed mistake with mutable default arguments

Co-authored-by: Christian Clauss <cclauss@me.com>

* Updated handling for optional arguments

Co-authored-by: Christian Clauss <cclauss@me.com>

* Changed return statement to tuple

Made function return a tuple instead of a list

* Added more doctests

* Fixed spelling mistakes

* black . - reformatted decrypt_caesar_with_chi_squared.py

* Updated if statements to fit the updated code

* Minimized amount of lines in the code.

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-05-06 19:42:18 +02:00
Christian Clauss
6acd7fb5ce
Wrap lines that go beyond GitHub Editor (#1925)
* Wrap lines that go beyond GiHub Editor

* flake8 --count --select=E501 --max-line-length=127

* updating DIRECTORY.md

* Update strassen_matrix_multiplication.py

* fixup! Format Python code with psf/black push

* Update decision_tree.py

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-05-01 23:36:35 +02:00
Christian Clauss
1ad78b2663
Fix invalid escape sequence in binary_search_tree.py (#1920)
* Fix invalid escape sequence in binary_search_tree.py

data_structures/binary_tree/binary_search_tree.py:156
  /home/travis/build/TheAlgorithms/Python/data_structures/binary_tree/binary_search_tree.py:156: DeprecationWarning: invalid escape sequence \

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-05-01 02:17:11 +05:30
LethargicLeprechaun
fbc038d532
Added A1Z26 Cipher (#1914)
* A1Z26 Cipher

* A1Z26 Cipher

* Added type hints

* Added Doctests

* removed tabs, spaces instead

* corrected doctest

* corrected doctest

* info URLs added

* Condensed decode to one line

* Condensed encode function to a single line

* Nice one!

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-04-30 00:23:51 +02:00
Christian Clauss
b1377f0e57
autoblack: actions/checkout@v1 # Use v1, NOT v2 (#1796)
* autoblack: actions/checkout@v1  # Use v1, NOT v2

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-03-13 09:23:38 +01:00
Aakash Dinkar
182e3042f8
update rot13.py (#1790)
* update rot13.py

* Update rot13.py

* Type hints, doctests, URL to Wikipedia

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-03-08 07:04:21 +01:00
matkosoric
7f04e5cd34
contribution guidelines checks (#1787)
* spelling corrections

* review

* improved documentation, removed redundant variables, added testing

* added type hint

* camel case to snake case

* spelling fix

* review

* python --> Python # it is a brand name, not a snake

* explicit cast to int

* spaces in int list

* "!= None" to "is not None"

* Update comb_sort.py

* various spelling corrections in documentation & several variables naming conventions fix

* + char in file name

* import dependency - bug fix

Co-authored-by: John Law <johnlaw.po@gmail.com>
2020-03-04 13:40:28 +01:00
onlinejudge95
7b7c1a0135
Fixes unused variable errors in LGTM (#1746)
* Fixes unsed variable errors in LGTM

* Fixes integer check

* Fixes failing tests
2020-02-11 13:59:09 +05:30
Christian Clauss
670f952aa6
Travis CI: Don’t allow bare exceptions (#1734)
* Travis CI: Don’t allow bare exceptions

* fixup! Format Python code with psf/black push

* except IOError:

* except IOError:

* Update hamming_code.py

* IndexError

* Get rid of the nonsense logic

Co-authored-by: John Law <johnlaw.po@gmail.com>
2020-02-07 22:02:08 +02:00
tania-cmyk
74a7b5f799
relevant documentation added (#1725) 2020-02-03 14:30:58 +05:30
Christian Clauss
bfcb95b297
Create codespell.yml (#1698)
* fixup! Format Python code with psf/black push

* Create codespell.yml

* fixup! Format Python code with psf/black push
2020-01-18 13:24:33 +01:00
Christian Clauss
28419cf839 pyupgrade --py37-plus **/*.py (#1654)
* pyupgrade --py37-plus **/*.py

* fixup! Format Python code with psf/black push
2020-01-03 22:25:36 +08:00
Christian Clauss
34c808b375 actions/checkout@v2 (#1643)
* actions/checkout@v2

https://github.com/actions/checkout/releases

* fixup! Format Python code with psf/black push
2019-12-26 19:50:12 +08:00
Saransh Gupta
1d9266eca0 Fixed warning string for Key B = 0 (#1639)
* Fixed warning string for Key B = 0

* Update affine_cipher.py

* Update affine_cipher.py

* decrypt_message(encrypt_message())

Co-authored-by: Christian Clauss <cclauss@me.com>
2019-12-20 23:52:43 +01:00
GeorgeChambi
9eb50cc223 Improved readability (#1615)
* improved readability

* further readability improvements

* removed csv file and added f
2019-12-07 06:39:59 +01:00
GeorgeChambi
8ffc4f8706 fixed bug (#1610)
Removed comma from print statement causing and error.
2019-12-03 12:14:30 +01:00
achance6
2ad5a1f083 Implemented simple keyword cipher (#1589)
* Implemented simple keyword cipher

* Added documentation and improved input processing

* Allow object's hash function to be called

* added to string functionality

* reverted

* Revised according to pull request #1589

* Optimized imports

* Update simple_keyword_cypher.py

* Update hash_table.py
2019-11-23 16:52:32 +01:00
Christian Clauss
b838f1042c Fix indentation contains tabs (flake8 E101,W191) (#1573) 2019-11-15 23:05:00 -08:00
Zizhou Zhang
e3aa0f65e8 fix implementation errors. (#1568)
I revised my implementation and found out that I have miss a inner loop for t.  x and y should be recalculated everytime when t is divisble by 2. I have also included a more readble source for this algorithm.
2019-11-14 20:29:54 +01:00
Christian Clauss
5df8aec66c
GitHub Action formats our code with psf/black (#1569)
* GitHub Action formats our code with psf/black

@poyea Your review please.

* fixup! Format Python code with psf/black push
2019-11-14 19:59:43 +01:00
Zizhou Zhang
db515e585e added rsa_factorization.py (#1556)
* added RSA_factorization.py

This algorithm can effectively factor RSA large prime N given public key e and private key d.

* Rename RSA_factorization.py to rsa_factorization.py

* Add definitions for d, e, and N
2019-11-09 15:02:30 +01:00
Marvin M. Michum
5452e94528 Porta cipher (#1550)
* directory_writer

* add porta cipher for #1492

* formatting and one line comprehensions

* remove directory_writer

* indentions

* Wrap long lines
2019-11-04 08:45:29 +01:00
Sri Suma
fc533a7598 Simplified DES (#1382)
* Simplified DES

* Add files via upload

Diffie Hellman algorithm to generate a secret key.

* Update sdes.py

* Format code with psf/black and add doctests
2019-10-30 12:52:20 +01:00
arjun1299
e36fe34b0b Hard coded inputs to mixed_keyword cypher (#1500)
* Update morse_code_implementation.py

* Delete porta_cipher.py

* Update mixed_keyword_cypher.py

* Mixed keyword cypher added

* issue with mixed keyword fixed

* no math included

* hardcoded inputs

* porta cypher added

* porta cypher added

* commented in mixed keyword according to contrib.md
2019-10-28 13:06:28 +01:00
bizzfitch
182062d60b Adding deterministic miller rabin primality test (#1453)
* Adding deterministic miller rabin primality test

* Moved to ciphers directory and renamed for clarity. Changed docstring to add test
2019-10-25 19:04:06 +02:00
Ankur Chattopadhyay
d477a4ddf2 introduced shuffled_shift_cipher.py in /ciphers (#1424)
* introduced shuffled_shift_cipher.py in /ciphers

* made requested changes

* introduced doctests, type hints
removed __make_one_digit()

* test_end_to_end() inserted

* Make test_end_to_end() a test ;-)
2019-10-23 20:20:38 +02:00
Ankur Chattopadhyay
7592cba417 psf/black code formatting (#1421)
* added sol3.py for problem_20

* added sol4.py for problem_06

* ran `black .` on `\Python`
2019-10-22 19:13:48 +02:00
Pierrick
e177198177 Add unicode support in ciphers/base64_cipher.py script. (#1316)
* Add unicode support in ciphers/base64_cipher.py script.

* Add doctests and correct the padding length computation in base64_cipher.
2019-10-18 08:35:13 +02:00
Yurii
b7fb0630f2 Feature/fix caesar cipher (#1350)
* change var names for better reading

* rewrite encrypt function to fix ascii char ranges

* fix decrypt function

* update formatting (add f-strings)

* upd fuctions

* add f-string formatting (python3.6+)

* add type hints (python3.4+)
2019-10-18 07:36:52 +02:00
William Zhang
9eac17a408 psf/black code formatting (#1277) 2019-10-05 10:14:13 +05:00
Christian Clauss
47a9ea2b0b
Simplify code by dropping support for legacy Python (#1143)
* Simplify code by dropping support for legacy Python

* sort() --> sorted()
2019-08-19 15:37:49 +02:00
Christian Clauss
89acf5d017 print() is a function just like every other function (#1101)
* print() is a function just like every other function
2019-08-06 12:14:23 +02:00
Alfonso Rodríguez Pereira
5f991f7740 #315 Renamed all files to snake_case (#993) 2019-07-11 11:16:42 +02:00
cclauss
b7f13d991c Travis CI: Run black, doctest, flake8, mypy, and pytest (#964)
* Travis CI: Add type checking with mypy

* Create requirements.txt

* script: mypy --ignore-missing-stubs=cv2,numpy .

* Delete requirements.txt

* script: mypy --ignore-missing-imports .

* Run doctests

* Disable doctest -v other/detecting_english_programmatically.py

* Pytest

* No |

* pytest || true

* Run black doctest flake8 mypy pytest

* after_success: Build Directory.md

* Typo in filename: Dictionary.txt --> dictionary.txt'

Discovered via doctest run in #964

* python -m doctest -v

* pip install black flake8 mypy pytest

* pytest --doctest-glob='*.py'

* pytest --doctest-modules

* pytest --doctest-modules ./sorts

* pytest --doctest-modules ./ciphers ./other ./searches ./sorts ./strings || true

* if __name__ == "__main__":

* if __name__ == "__main__":

* if __name__ == '__main__':

* if __name__ == '__main__':

* if __name__ == '__main__':

* Create requirements.txt

* Update requirements.txt

* if __name__ == "__main__":

* Lose the doctests

* if __name__ == '__main__':

* Remove print-a-tuple

* doctest: Added missing spaces

* Update tabu_search.py

* The >>> are not doctests so change to >>)

* Travis CI: Run black, doctest, flake8, mypy, and pytest

* Link to the separate DIRECTORY.md file

* Update README.md
2019-07-08 23:27:51 +08:00
PatOnTheBack
26df2aab1e Removed Unused import sys (#922)
I removed `import sys` because it is not used in the program.
This addresses a [recommendation from lgtm](66c4afbd0f/files/ciphers/caesar_cipher.py)
2019-07-06 23:35:12 +08:00
cclauss
0f229e0870 Atbash.py: Both raw_input() and unichr() were removed in Python 3 (#855)
* Atbash.py: Both raw_input() and unichr() were removed in Python 3

@sateslayer and @AnupKumarPanwar your reviews please.

* Remove any leading / trailing whitespace from user input
2019-06-05 09:09:04 +08:00
Anup Kumar Panwar
f56dd7f8e3
Update Atbash.py 2019-05-26 22:59:07 +05:30
Shubhayu Das
5be32f4022 Add files via upload (#396) 2019-05-26 22:10:04 +05:30
Ambuj81
7f4f565e62 subset_generation (#326)
* subset_generation

generate all possible subset of size n of a given array of size r

* Rename subset_generation to subset_generation.py

* Update subset_generation.py

I made all changes I could  . What I mean is I removed all the empty space ....... 
There some comment extra if you feel removing those comments please do so yourself pls provide spacing as it should be

* Create morse_Code_implementation.py

* Any more changes pls let me know
2019-05-26 22:07:40 +05:30
nowakowsky
5b7730bef1 Added Trafid Cipher (#746) 2019-04-04 03:27:36 +08:00
Sravan Kumar Vinakota
2b27086c00 Added hill_cipher.py (#696)
A python class that implements the Hill cipher algorithm.
2019-02-22 00:19:28 +08:00
Abhi Kampurath
ad68eed73e Update caesar_cipher.py (#702) 2019-02-19 23:26:09 +08:00
Michael Fried
c92b02cfa3 Editing base64, Adding average file, Editing find_lcm (#673)
* avrage.py

calculate and print the avrage of number list.

* Update base64_cipher.py

encoding and decoding base64 without any module.

* Update and rename avrage.py to average.py

* update find_lcm algorithm

I made find_lcm more efficient form O(num1*num2) to O(min{num1,num2}).
2019-01-20 02:19:06 +05:30
Mickaël Schoentgen
2d70e9f747 Fix ResourceWarning: unclosed file (#681)
Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
2019-01-08 16:59:23 +08:00
Mickaël Schoentgen
3dc50529ca Fix DeprecationWarning: invalid escape sequence (#679)
Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
2019-01-08 16:58:47 +08:00
gerroo
a834326e0e Added b16, b32, a85, abs, absMax, absMin 2018-11-03 12:08:13 -08:00
gerroo
fde422e217 base64
added b64
2018-10-28 13:36:51 -08:00
Harshil
4e0184a41d
Update caesar_cipher.py
Removed unnecessary recursion and updated code!
2018-10-27 14:14:35 +02:00
Harshil
2638d57c71
Update caesar_cipher.py 2018-10-24 21:13:42 +02:00
Alex Brown
ea2ddaaf6a all valid python 3 2018-10-20 14:45:08 -05:00
Alex Brown
b566055e4b Merge branch 'master' of https://github.com/TheAlgorithms/Python 2018-10-20 14:15:21 -05:00
Jonathan Gómez
c0f7df7e22 Fixed error on chr function when decrypt (#359)
On line 23 when make the operations returns a float and chr function doesn't permit float values as parameters.
2018-10-19 15:42:19 +02:00
Alex Brown
564179a0ec increment 1 2018-10-19 07:48:28 -05:00
Alex Brown
718b99ae39 increment 1 2018-10-19 07:48:01 -05:00
Parth Shandilya
5d1f72604d
Improved Code and removed Warnings (#483) 2018-10-19 14:00:31 +05:30
ParthS007
0856a61859 Remove Multiple Unused Imports and Variable 2018-10-18 02:58:57 +05:30
cclauss
3a77380ed3 Undefined name: import random in Onepad_Cipher.py (#339) 2018-09-28 09:47:28 +05:30
cclauss
d4594da532
print() is a function in Python 3 2018-07-02 10:07:25 +02:00
psyas
0c8707d11c Elgamal cipher key generator code - (initial) 2018-06-12 21:21:38 +09:00
psyas
602eae756e Elgamal cipher key generator code - (initial) 2018-06-12 21:18:50 +09:00
Harshil
13617225ca
small improvements! 2018-05-28 23:25:48 +02:00
PyDevthon
f1fe458356
Updated_caesar_cipher.py
Updated
2018-05-28 19:16:02 +05:30
Syed Haseeb Shah
0fdd2d369e
Create Onepad_Cipher.py
In one pad algorithm length of key and length of message are equal which results in endless possibilities of false messages on bruteforce.
2018-04-13 20:49:38 +05:00
ashu01
4fb978cf58 1. typo fix {playfair_cipher.py, AVL.py}
2. Corrected Logic {AVL.py, 104-107}
3. Removed unnecessary semicolons {BellmanFord.py, Dijkstra.py}
2017-12-31 14:30:31 +05:30
Harshil
09cc769660
Merge pull request #220 from cclauss/modernize-python2-code
Modernize Python 2 code to get ready for Python 3
2017-12-29 17:19:02 +05:30
Harshil
eb9fe88e16
Merge pull request #230 from christianbender/master
improvement XOR_cipher.py
2017-12-23 18:25:38 +05:30
Christian Bender
0e7d4483ca
comment out
I comment out some code lines in the test-section
2017-12-22 17:33:09 +01:00
Christian Bender
b25bc2cb30
improvement
I improve my code
2017-12-22 17:30:11 +01:00
Harshil
ecdfd99c04
Merge pull request #229 from christianbender/master
XOR cipher algorithm
2017-12-22 18:24:43 +05:30
Christian Bender
ad265b9b61
XOR cipher algorithm
a class with simple cipher algorithm that uses bitwise XOR
2017-12-21 19:08:58 +01:00
cclauss
e31c780d94 Modernize Python 2 code to get ready for Python 3 2017-11-25 12:41:55 +01:00
cclauss
aed9cb16ec
chunk() --> chuncker() to resolve undefined name
flake8 results:
```
./ciphers/playfair_cipher.py:88:25: F821 undefined name 'chunk'
    for char1, char2 in chunk(ciphertext, 2):
                        ^
```
2017-11-25 12:15:41 +01:00
cclauss
4e06949072 Modernize Python 2 code to get ready for Python 3 2017-11-25 10:23:50 +01:00
Pedro Tôrres
75af340aff ROT13 2017-10-29 14:44:54 -03:00
eevee
73461baeb0 Playfair cipher 2017-08-18 22:41:46 -04:00
Henocks
43513803f0 Slight Performance/Visual Update 2016-11-09 23:17:04 +09:00
Harshil Darji
f5c73a6f26 initial 2016-09-06 17:53:48 +05:30
Harshil Darji
1376e3c3b9 Initial 2016-08-11 18:14:46 +05:30
Harshil Darji
cf8191130d Initial 2016-08-07 21:18:46 +05:30
Harshil Darji
f68690f296 Added test cases 2016-08-02 23:16:55 +05:30
Harshil Darji
8926cc0a30 Cryptography Algorithm 2016-08-02 13:41:36 +05:30
Harshil Darji
5b72d5e0a1 Cryptography Algorithm 2016-08-01 22:41:06 +05:30
Harshil Darji
005fb0c5a1 File rename 2016-08-01 21:33:08 +05:30
Sergey Tsaplin
ab2614574e Move files to separate directories 2016-08-01 15:06:53 +05:00