Skip to content

Commit

Permalink
Merge pull request #15 from D-ENCODER/dev
Browse files Browse the repository at this point in the history
Polybius Cipher encryption and decryption algorithms added
  • Loading branch information
D-ENCODER authored Oct 8, 2022
2 parents 7cd481f + 46be44d commit 586be0a
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 3 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,15 @@ from kryptor.blowfish_cipher import BlowfishCipher
obj = BlowfishCipher()
print(obj.encrypt(1684)) # returns 8301200985422371632
print(obj.decrypt(8301200985422371632)) # returns 1684
```
### POLYBIUS CIPHER

---

```python
from kryptor.polybius_cipher import PolybiusCipher

obj = PolybiusCipher()
print(obj.encrypt("I am Dencoder")) # returns 24 1132 1415331334141542
print(obj.decrypt("24 1132 1415331334141542")) # returns i am dencoder
```
Binary file added dist/kryptor-0.5.0-py3-none-any.whl
Binary file not shown.
Binary file added dist/kryptor-0.5.0.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "kryptor"
version = "0.4.0"
version = "0.5.0"
authors = [
{ name="Het Joshi (DENCODER)", email="hetcjoshi1684@gmail.com" },
]
Expand Down
15 changes: 13 additions & 2 deletions src/kryptor.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: kryptor
Version: 0.4.0
Version: 0.5.0
Summary: Encrypt and Decrypt data with famous cryptography techniques
Author-email: "Het Joshi (DENCODER)" <hetcjoshi1684@gmail.com>
License: GNU GENERAL PUBLIC LICENSE
Expand Down Expand Up @@ -796,7 +796,7 @@ obj = VernamCipher()
print(obj.encrypt("I am Dencoder", "Python Coder")) # returns xyfksaecgii
print(obj.decrypt("xyfksaecgii", "Python Coder")) # returns iamdencoder
```
# BLOWFISH CIPHER
### BLOWFISH CIPHER

---

Expand All @@ -807,3 +807,14 @@ obj = BlowfishCipher()
print(obj.encrypt(1684)) # returns 8301200985422371632
print(obj.decrypt(8301200985422371632)) # returns 1684
```
### POLYBIUS CIPHER

---

```python
from kryptor.polybius_cipher import PolybiusCipher

obj = PolybiusCipher()
print(obj.encrypt("I am Dencoder")) # returns 24 1132 1415331334141542
print(obj.decrypt("24 1132 1415331334141542")) # returns i am dencoder
```
1 change: 1 addition & 0 deletions src/kryptor.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ src/kryptor/hill_cipher.py
src/kryptor/img_steganography.py
src/kryptor/morse.py
src/kryptor/playfair_cipher.py
src/kryptor/polybius_cipher.py
src/kryptor/rail_fence.py
src/kryptor/vernam_cipher.py
src/kryptor/vigenere_cipher.py
Expand Down
55 changes: 55 additions & 0 deletions src/kryptor/polybius_cipher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Date : 08/10/22 7:45 pm
# Author : dencoder (hetcjoshi1684@gmail.com)
# GitHub : (https://github.com/D-ENCODER)
# Twitter : (https://twitter.com/Hetjoshi1684)
# Version : 1.0.0
import numpy as np


class PolybiusCipher:
def __init__(self):
SQUARE = [
["a", "b", "c", "d", "e"],
["f", "g", "h", "i", "k"],
["l", "m", "n", "o", "p"],
["q", "r", "s", "t", "u"],
["v", "w", "x", "y", "z"],
]
self.SQUARE = np.array(SQUARE)
self._plaintext = ""
self._ciphertext = ""

def _letter_to_numbers(self, letter):
index1, index2 = np.where(self.SQUARE == letter)
indexes = np.concatenate([index1 + 1, index2 + 1])
return indexes

def _numbers_to_letter(self, index1: int, index2: int) -> str:
return self.SQUARE[index1 - 1, index2 - 1]

def encrypt(self, plaintext):
self._plaintext = plaintext.replace("j", "i").lower()
self._ciphertext = ""
for letter_index in range(len(self._plaintext)):
if self._plaintext[letter_index] != " ":
numbers = self._letter_to_numbers(self._plaintext[letter_index])
self._ciphertext = self._ciphertext + str(numbers[0]) + str(numbers[1])
elif self._plaintext[letter_index] == " ":
self._ciphertext = self._ciphertext + " "

return self._ciphertext

def decrypt(self, ciphertext):
self._ciphertext = ciphertext.replace(" ", " ")
self._plaintext = ""
for numbers_index in range(int(len(self._ciphertext) / 2)):
if self._ciphertext[numbers_index * 2] != " ":
index1 = self._ciphertext[numbers_index * 2]
index2 = self._ciphertext[numbers_index * 2 + 1]

letter = self._numbers_to_letter(int(index1), int(index2))
self._plaintext = self._plaintext + letter
elif self._ciphertext[numbers_index * 2] == " ":
self._plaintext = self._plaintext + " "

return self._plaintext

0 comments on commit 586be0a

Please # to comment.