예제 #1
0
파일: test.py 프로젝트: brasse/ciphersaber
def main():
    for test_file, key, n, expected_hash in TEST_FILES:
        with open(os.path.join(TEST_FILES_DIR, test_file), 'rb') as f:
            out_stream = StringIO.StringIO()
            ciphersaber.process(False, f, key, n, out_stream)

            hash = hashlib.md5(out_stream.getvalue()).hexdigest()

            if hash == expected_hash:
                print '%s OK' % test_file
            else:
                print 'Failed to decrypt %s' % test_file
                print 'Expected hash:  %s' % expected_hash
                print 'Resulting hash: %s' % hash
                return 1

    print 'All files decrypted correctly!'
    return 0
예제 #2
0
def decrypt(encrypted_text, key, n=__N_DEFAULT):
    fin = StringIO.StringIO(base64.standard_b64decode(encrypted_text))
    fout = StringIO.StringIO()

    ciphersaber.process(False, fin, key, n, fout)
    return fout.getvalue()
예제 #3
0
def encrypt(plain_text, key, n=__N_DEFAULT):
    fin = StringIO.StringIO(plain_text)
    fout = StringIO.StringIO()
    
    ciphersaber.process(True, fin, key, n, fout)
    return base64.standard_b64encode(fout.getvalue())