-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from D-ENCODER/dev
Polybius Cipher encryption and decryption algorithms added
- Loading branch information
Showing
7 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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="[email protected]" }, | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" <[email protected]> | ||
License: GNU GENERAL PUBLIC LICENSE | ||
|
@@ -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 | ||
|
||
--- | ||
|
||
|
@@ -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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Date : 08/10/22 7:45 pm | ||
# Author : dencoder ([email protected]) | ||
# 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 |