Exemple #1
0
def callAction(choice):
    if (choice == 0):
        auto_compute_p_and_generator_encryption_decryption()
        return 1

    if (choice == 1):
        print '_______________________________________________'
        print 'Public-key cryptography computes key files'
        m = input('Enter your computed modulo: ')
        g = input('Enter your computed generator: ')
        pri = input('Enter your private key: ')
        crypto.setupKeyFiles(m, g, pri)
        printKeyFiles()
        return 1

    if (choice == 2):
        print '_______________________________________________'
        print 'Public-key cryptography computes key files'
        pri = input('Enter your private key: ')
        if (crypto.computeKeyFiles(pri)): printKeyFiles()
        return 1

    if (choice == 3):
        print '_______________________________________________'
        print 'Write a plaintext'
        create_plaintext_file()
        with open(crypto.ptextfname, 'r') as f:
            print f.read()
        return 1

    if (choice == 4):
        print '_______________________________________________'
        print 'Public-key cryptography ENCRYPTION'
        if (not checkFileExist(crypto.pubkeyfname) or
            not checkFileExist(crypto.prikeyfname) or
            not checkFileExist(crypto.ptextfname)):
            print 'No required files for encryption'
            return 1
        crypto.encrypt()
        print 'Done'
        return 1

    if (choice == 5):
        print '_______________________________________________'
        print 'Public-key cryptography DECRYPTION'
        if (not checkFileExist(crypto.pubkeyfname) or
            not checkFileExist(crypto.prikeyfname) or
            not checkFileExist(crypto.ptextfname)):
            print 'No required files for decryption'
            return 1        
        crypto.decrypt()
        with open(crypto.dtextfname, 'r') as f:
            print f.read()
        print 'Done'
        return 1

    return 0
    def test_encrytion_short_msg(self):
        crypto.setupKeyFiles(self.p, self.e1, self.d)

        with open(crypto.ptextfname, 'w') as f:
            f.write(self.shorttext)

        crypto.encrypt()
        crypto.decrypt()

        with open(crypto.dtextfname, 'r') as f:
            lines = f.readlines()
            self.assertEqual(1, len(lines))
            self.assertEqual(self.shorttext, lines[0])
    def test_encrytion_two_lines(self):
        crypto.setupKeyFiles(self.p, self.e1, self.d)

        with open(crypto.ptextfname, 'w') as f:
            f.write(self.text)
            f.write('\n')
            f.write(self.text1)

        crypto.encrypt()
        crypto.decrypt()

        with open(crypto.dtextfname, 'r') as f:
            lines = f.readlines()
            self.assertEqual(2, len(lines))
            self.assertEqual(self.text, lines[0].replace('\n', ''))
            self.assertEqual(self.text1, lines[1])
Exemple #4
0
def setup_key_files_encryption_decryption():
    print '_______________________________________________'
    print 'Public-key cryptography computes key files'
    crypto.setupKeyFiles(p, e1, prikey)
    printKeyFiles()

    print '_______________________________________________'
    print 'Write a plaintext'
    create_plaintext_file()
    with open(crypto.ptextfname, 'r') as f:
        print f.read()

    print '_______________________________________________'
    print 'Public-key cryptography ENCRYPTION'
    crypto.encrypt()

    print '_______________________________________________'
    print 'Public-key cryptography DECRYPTION'
    crypto.decrypt()
    with open(crypto.dtextfname, 'r') as f:
        print f.read()

    print '\nDone!!!'
Exemple #5
0
def auto_compute_p_and_generator_encryption_decryption():
    print '_______________________________________________'
    print 'Public-key cryptography computes key files'
    crypto.computeKeyFiles(prikey)
    printKeyFiles()

    print '_______________________________________________'
    print 'Write a plaintext'
    create_plaintext_file()
    with open(crypto.ptextfname, 'r') as f:
        print f.read()

    print '_______________________________________________'
    print 'Public-key cryptography ENCRYPTION'
    crypto.encrypt()

    print '_______________________________________________'
    print 'Public-key cryptography DECRYPTION'
    crypto.decrypt()
    with open(crypto.dtextfname, 'r') as f:
        print f.read()

    print '\nDone!!!'