-
-
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 #6 from D-ENCODER/dev
Rail Fence algorithm added
- Loading branch information
Showing
7 changed files
with
84 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.1.5" | ||
version = "0.2.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.1.5 | ||
Version: 0.2.0 | ||
Summary: Encrypt and Decrypt data with famous cryptography techniques | ||
Author-email: "Het Joshi (DENCODER)" <[email protected]> | ||
License: GNU GENERAL PUBLIC LICENSE | ||
|
@@ -688,7 +688,7 @@ Description-Content-Type: text/markdown | |
License-File: LICENSE | ||
|
||
# KRYPTOR | ||
[](https://github.com/D-ENCODER/KRYPTOR/issues) [](https://github.com/D-ENCODER/KRYPTOR/network) [](https://github.com/D-ENCODER/KRYPTOR/stargazers) [](https://github.com/D-ENCODER/KRYPTOR/blob/master/LICENSE) [](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2FD-ENCODER%2FKRYPTOR) | ||
[](https://github.com/D-ENCODER/KRYPTOR/issues) [](https://github.com/D-ENCODER/KRYPTOR/network) [](https://github.com/D-ENCODER/KRYPTOR/stargazers) [](https://github.com/D-ENCODER/KRYPTOR/blob/master/LICENSE) [](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2FD-ENCODER%2FKRYPTOR) [](https://codeclimate.com/github/D-ENCODER/KRYPTOR/maintainability)  | ||
### CAESAR CIPHER | ||
|
||
--- | ||
|
@@ -774,3 +774,14 @@ obj = VigenereCipher() | |
print(obj.encrypt('I am Dencoder', 'key')) # returns s ek nilmsbov | ||
print(obj.decrypt('s ek nilmsbov', 'key')) # returns i am dencoder | ||
``` | ||
### RAIL FENCE CIPHER | ||
|
||
--- | ||
|
||
```python | ||
from kryptor.rail_fence import RailFence | ||
|
||
obj = RailFence() | ||
print(obj.encrypt('I am Dencoder', 3)) # returns iedadnoemcr | ||
print(obj.decrypt('iedadnoemcr', 3)) # returns iamdencoder | ||
``` |
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,58 @@ | ||
# Date : 04/10/22 6:19 pm | ||
# Author : dencoder ([email protected]) | ||
# GitHub : (https://github.com/D-ENCODER) | ||
# Twitter : (https://twitter.com/Hetjoshi1684) | ||
# Version : 1.0.0 | ||
|
||
class RailFence: | ||
def __init__(self): | ||
self._key = '' | ||
self._ciphertext = '' | ||
self._plaintext = '' | ||
|
||
@staticmethod | ||
def _sequence(key): | ||
arr = [] | ||
i = 0 | ||
while i < key - 1: | ||
arr.append(i) | ||
i += 1 | ||
while i > 0: | ||
arr.append(i) | ||
i -= 1 | ||
return arr | ||
|
||
def encrypt(self, plaintext, key): | ||
self._plaintext = plaintext.replace(' ', '').lower() | ||
self._ciphertext = "" | ||
self._key = key | ||
L = self._sequence(self._key) | ||
temp = L | ||
while len(self._plaintext) > len(L): | ||
L = L + temp | ||
for _ in range(len(L) - len(self._plaintext)): | ||
L.pop() | ||
num = 0 | ||
while num < self._key: | ||
for i in range(L.count(num)): | ||
self._ciphertext = self._ciphertext + self._plaintext[L.index(num)] | ||
L[L.index(num)] = self._key | ||
num += 1 | ||
return self._ciphertext | ||
|
||
def decrypt(self, ciphertext, key): | ||
self._ciphertext = ciphertext.lower() | ||
self._plaintext = "" | ||
self._key = key | ||
L = self._sequence(self._key) | ||
temp = L | ||
while len(self._ciphertext) > len(L): | ||
L = L + temp | ||
for i in range(len(L) - len(self._ciphertext)): | ||
L.pop() | ||
temp = sorted(L) | ||
for i in L: | ||
k = temp.index(i) | ||
temp[k] = self._key | ||
self._plaintext += self._ciphertext[k] | ||
return self._plaintext |