示例#1
0
 def test_decrypt(self):
     for i, alphabet in enumerate(self.alphabet):
         dec = Caesar().decrypt(self.ciphertext[i], self.key[i], alphabet)
         self.assertEqual(dec, self.plaintext[i])
示例#2
0
    msg_lst.extend('_' * fill_null)

    matrix = [msg_lst[i:i + col] for i in range(0, len(msg_lst), col)]

    for _ in range(col):
        curr_idx = key.index(key_lst[k_indx])
        cipher += ''.join([row[curr_idx] for row in matrix])
        k_indx += 1

    return cipher


if int(pilihan) == 1:
    pt = input('Masukkan plaintext: ')
    kc = int(input('Masukkan key: '))
    kesar = Caesar().encrypt(pt, kc)
    print(f'\nCiphertext: {kesar.upper()}')

elif int(pilihan) == 3:
    pt = input('Masukkan plaintext: ')
    kc = int(input('Masukkan depth: '))
    keretapi = railfence(pt, kc)
    print(f'\nCiphertext: {keretapi.upper()}')

elif int(pilihan) == 4:
    pt = input('Masukkan plaintext: ')
    kc = input('Masukkan key: ')
    tukarbaris = rowtransposition(pt, kc)
    print(f'\nCiphertext: {tukarbaris.upper()}')

elif int(pilihan) == 5:
#Help Received: https://readthedocs.org/projects/secretpy/downloads/pdf/stable/
from secretpy import Caesar
for i in range(26):
    print(i)
    print(Caesar().decrypt("VRUXKWXYXGLXYNGWTFXGMTEL".lower(), i))
示例#4
0
from secretpy import Atbash, Caesar, CryptMachine, alphabets
from secretpy.cmdecorators import SaveAll


def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)
    print("-----------------------------------")


plaintext = u"thequickbrownfoxjumpsoverthelazydog"
key = 3
cipher = Caesar()

cm = CryptMachine(cipher, key)
encdec(cm, plaintext)

cm.set_alphabet(alphabets.GERMAN)
encdec(cm, plaintext)

cm1 = SaveAll(cm)
cm1.set_key(9)
plaintext = u"the quick brown fox jumps over the lazy dog"
encdec(cm1, plaintext)

cm2 = cm
cm2.set_cipher(Atbash())
plaintext = u"Achtung Minen"
def Decryp_ceaser():
    data = input("Enter dtata to be Decrypted By Ceaser Algorithm : ")
    key = int(input("Enter key to be Ency : "))
    cm = SaveSpaces(SaveCase(CryptMachine(Caesar(), key)))
    print(cm.decrypt(data))
    input("Copy if needed.............")
示例#6
0

def encdec(machine, plaintext):
    print("=======================================")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)


key = 5
plaintext = u"Dog jumps four times and cat six times"
print(plaintext)

cm1 = SaveAll(CryptMachine(Caesar(), key))
enc = cm1.encrypt(plaintext)
print(enc)

cm2 = SaveAll(CryptMachine(Rot13()))
enc = cm2.encrypt(enc)
print(enc)

print("=======================================")

cm = CompositeMachine(cm1)
cm.add_machines(cm2)
enc = cm.encrypt(plaintext)
print(enc)
encdec(cm, plaintext)
def Encryp_ceaser():
    data = input("Enter data to be Encrypted with Ceaser algorithm : ")
    key = int(input("Enter key : "))
    cm = SaveSpaces(SaveCase(CryptMachine(Caesar(), key)))
    print(cm.encrypt(data))
    input("Copy if needed.............")
def Decryp_ceaser_t(arg1, arg2):
    data = arg1
    key = int(arg2)
    cm = SaveSpaces(SaveCase(CryptMachine(Caesar(), key)))
    return(cm.decrypt(data))
示例#9
0
#!/usr/bin/python3

from secretpy import alphabets
from secretpy import Caesar
from ngramscore import NGramScore 


alphabet = alphabets.GERMAN

fitness = NGramScore('freq/de-2.txt')
cipher = Caesar()

def crack(ctext):
    max_score = 0 
    key = 0 
    for i in range(0, len(alphabet)):
        dec = cipher.decrypt(ctext, i, alphabet)
        score = fitness.score(dec)
        print("key = " + str(i) + ", decrypted text: " + str(dec.upper()) + ", score: " + str(score))
        if score > max_score:
            max_score = score
            key = i
    return key 

# example ciphertext
enc = 'äbööemökglbgäßnm'
print("encrypted text: " + enc)
print()

key = crack(enc)
示例#10
0

def encdec(machine, plaintext):
    print("=======================================")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)


key = 5
plaintext = u"Dog jumps four times and cat six times"
print(plaintext)

cm1 = SaveSpaces(SaveCase(CryptMachine(Caesar(), key)))
enc = cm1.encrypt(plaintext)
print(enc)

cm2 = SaveSpaces(SaveCase(CryptMachine(Rot13())))
enc = cm2.encrypt(enc)
print(enc)

print("=======================================")

cm = CompositeMachine(cm1)
cm.add_machines(cm2)
enc = cm.encrypt(plaintext)
print(enc)

encdec(cm, plaintext)
示例#11
0
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Caesar
from secretpy import alphabets

alphabet = alphabets.GERMAN
plaintext = u"thequickbrownfoxjumpsoverthelazydog"
key = 3
cipher = Caesar()

print(plaintext)
enc = cipher.encrypt(plaintext, key, alphabet)
print(enc)
dec = cipher.decrypt(enc, key, alphabet)
print(dec)

print('=====================================')

print(plaintext)
# use default english alphabet
enc = cipher.encrypt(plaintext, key)
print(enc)
dec = cipher.decrypt(enc, key)
print(dec)
'''
Output:

thequickbrownfoxjumpsoverthelazydog
wkhtxlfneurzqirämxpsvryhuwkhodüögrj
thequickbrownfoxjumpsoverthelazydog