Skip to content

Commit

Permalink
Merge pull request #6 from D-ENCODER/dev
Browse files Browse the repository at this point in the history
Rail Fence algorithm added
  • Loading branch information
D-ENCODER authored Oct 4, 2022
2 parents 137b1b7 + 095f84d commit c360dfd
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 3 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,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
```
Binary file added dist/kryptor-0.2.0-py3-none-any.whl
Binary file not shown.
Binary file added dist/kryptor-0.2.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.1.5"
version = "0.2.0"
authors = [
{ name="Het Joshi (DENCODER)", email="[email protected]" },
]
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.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
Expand Down Expand Up @@ -688,7 +688,7 @@ Description-Content-Type: text/markdown
License-File: LICENSE

# KRYPTOR
[![GitHub issues](https://img.shields.io/github/issues/D-ENCODER/KRYPTOR)](https://github.com/D-ENCODER/KRYPTOR/issues) [![GitHub forks](https://img.shields.io/github/forks/D-ENCODER/KRYPTOR)](https://github.com/D-ENCODER/KRYPTOR/network) [![GitHub stars](https://img.shields.io/github/stars/D-ENCODER/KRYPTOR)](https://github.com/D-ENCODER/KRYPTOR/stargazers) [![GitHub license](https://img.shields.io/github/license/D-ENCODER/KRYPTOR)](https://github.com/D-ENCODER/KRYPTOR/blob/master/LICENSE) [![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Ftwitter.com%2FHetjoshi1684)](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2FD-ENCODER%2FKRYPTOR)
[![GitHub issues](https://img.shields.io/github/issues/D-ENCODER/KRYPTOR)](https://github.com/D-ENCODER/KRYPTOR/issues) [![GitHub forks](https://img.shields.io/github/forks/D-ENCODER/KRYPTOR)](https://github.com/D-ENCODER/KRYPTOR/network) [![GitHub stars](https://img.shields.io/github/stars/D-ENCODER/KRYPTOR)](https://github.com/D-ENCODER/KRYPTOR/stargazers) [![GitHub license](https://img.shields.io/github/license/D-ENCODER/KRYPTOR)](https://github.com/D-ENCODER/KRYPTOR/blob/master/LICENSE) [![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Ftwitter.com%2FHetjoshi1684)](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2FD-ENCODER%2FKRYPTOR) [![Maintainability](https://api.codeclimate.com/v1/badges/54258993e9092f59bf6a/maintainability)](https://codeclimate.com/github/D-ENCODER/KRYPTOR/maintainability) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/D-ENCODER/KRYPTOR?display_name=tag&style=plastic)
### CAESAR CIPHER

---
Expand Down Expand Up @@ -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
```
1 change: 1 addition & 0 deletions src/kryptor.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ src/kryptor/hill_cipher.py
src/kryptor/img_steganography.py
src/kryptor/morse.py
src/kryptor/playfair_cipher.py
src/kryptor/rail_fence.py
src/kryptor/vigenere_cipher.py
src/kryptor.egg-info/PKG-INFO
src/kryptor.egg-info/SOURCES.txt
Expand Down
58 changes: 58 additions & 0 deletions src/kryptor/rail_fence.py
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

0 comments on commit c360dfd

Please sign in to comment.