예제 #1
0
def test_encipher_hill():
    A = Matrix(2, 2, [1, 2, 3, 5])
    assert encipher_hill("ABCD", A) == "CFIV"
    A = Matrix(2, 2, [1, 0, 0, 1])
    assert encipher_hill("ABCD", A) == "ABCD"
    assert encipher_hill("ABCD", A, symbols="ABCD") == "ABCD"
    A = Matrix(2, 2, [1, 2, 3, 5])
    assert encipher_hill("ABCD", A, symbols="ABCD") == "CBAB"
    assert encipher_hill("AB", A, symbols="ABCD") == "CB"
    # message length, n, does not need to be a multiple of k;
    # it is padded
    assert encipher_hill("ABA", A) == "CFGC"
    assert encipher_hill("ABA", A, pad="Z") == "CFYV"
예제 #2
0
def test_encipher_hill():
    A = Matrix(2, 2, [1, 2, 3, 5])
    assert encipher_hill("ABCD", A) == "CFIV"
    A = Matrix(2, 2, [1, 0, 0, 1])
    assert encipher_hill("ABCD", A) == "ABCD"
    assert encipher_hill("ABCD", A, symbols="ABCD") == "ABCD"
    A = Matrix(2, 2, [1, 2, 3, 5])
    assert encipher_hill("ABCD", A, symbols="ABCD") == "CBAB"
    assert encipher_hill("AB", A, symbols="ABCD") == "CB"
    # message length, n, does not need to be a multiple of k;
    # it is padded
    assert encipher_hill("ABA", A) == "CFGC"
    assert encipher_hill("ABA", A, pad="Z") == "CFYV"
예제 #3
0
def test_encipher_hill():
    A = Matrix(2, 2, [1, 2, 3, 5])
    assert encipher_hill("ABCD", A) == "CFIV"
    A = Matrix(2, 2, [1, 0, 0, 1])
    assert encipher_hill("ABCD", A) == "ABCD"
    assert encipher_hill("ABCD", A, symbols="ABCD") == "ABCD"
    A = Matrix(2, 2, [1, 2, 3, 5])
    assert encipher_hill("ABCD", A, symbols="ABCD") == "CBAB"
    assert encipher_hill("AB", A, symbols="ABCD") == "CB"
    # n does not need to be a multiple of k
    assert encipher_hill("ABA", A) == "CFAA"
예제 #4
0
def test_encipher_hill():
    A = Matrix(2, 2, [1, 2, 3, 5])
    assert encipher_hill("ABCD", A) == "CFIV"
    A = Matrix(2, 2, [1, 0, 0, 1])
    assert encipher_hill("ABCD", A) == "ABCD"
    assert encipher_hill("ABCD", A, symbols="ABCD") == "ABCD"
    A = Matrix(2, 2, [1, 2, 3, 5])
    assert encipher_hill("ABCD", A, symbols="ABCD") == "CBAB"
    assert encipher_hill("AB", A, symbols="ABCD") == "CB"
    # n does not need to be a multiple of k
    assert encipher_hill("ABA", A) == "CFAA"
예제 #5
0
def encryptionMethodMatrix(file, matrix, status=0):
    try:
        with open(file, 'r') as fn:
            msg = fn.read()
            fn.close()
        key = Matrix(matrix)
        msgE = encipher_hill(msg, key)

        with open(file, 'w') as fn:
            fn.write(msgE)
            fn.close()
        if (not status):
            with open('private.key', 'w') as fn:
                matrix = [
                    " ".join([str(num) for num in i]) + "\n" for i in matrix
                ]
                fn.writelines(matrix)
                fn.close()
        print(
            "\nArchivo encriptado exitosamente. Protege la llave secreta private.key !!"
        )
    except ValueError as e:
        print("Error Técnico: " + str(e))
예제 #6
0
#pip install SymPy
from sympy.crypto.crypto import encipher_hill, decipher_hill
from sympy import Matrix

def getMatrix(msg):
    matrix=[[0 for x in range(3)] for y in range(3)]
    k=0
    for i in range(3):
        for j in range(3):
            matrix[i][j] = ord(msg[k])%65
            k+=1
    return matrix

message=input("Enter text: ")
key = Matrix(getMatrix("GYBNQKURP"))
cipher = encipher_hill(message, key)
print("Ciphered: ", cipher)
print("Deciphered:", decipher_hill(cipher, key))
예제 #7
0
from sympy.crypto.crypto import encipher_hill, decipher_hill
from sympy import Matrix

key = Matrix([[1, 2], [3, 5]])
a = raw_input("Write the pure text: ")
b = encipher_hill(a, key)
c = decipher_hill(b, key)
print b
print c

예제 #8
0
def hill(msg, key, **kwargs):
    et = encipher_hill(msg, key, symbols=symbols, pad="0")
    dt = decipher_hill(et, key, symbols=symbols)
    return et, dt
예제 #9
0
#pip install SymPy
from sympy.crypto.crypto import encipher_hill, decipher_hill
from sympy import Matrix
pt = "ACT"
key = Matrix([[6, 24, 1], [13, 16, 10], [20, 17, 15]])
ct = encipher_hill(pt, key)
print("Ciphered: ", ct)
print("Deciphered:", decipher_hill(ct, key))