示例#1
0
            try:
                c = text[i + j]
                plaintext += c
            except:
                pass
    return plaintext


def hack(text):
    for key in xrange(1, len(text)):
        p = decrypt(text, key).replace(placeholder, '')
        yield p

if __name__ == '__main__':
    m = raw_input('encrypt/decrypt/hack? ').lower()
    if 'encrypt'.startswith(m):
        text = raw_input('plaintext: ')
        key = int(raw_input('key: '))
        print 'ciphertext:', encrypt(text, key)
    elif 'decrypt'.startswith(m):
        text = raw_input('ciphertext: ')
        key = int(raw_input('key: '))
        p = decrypt(text, key)
        print 'plaintext:', p.replace(placeholder, '')
    elif 'hack'.startswith(m):
        text = raw_input('ciphertext: ')
        for p in hack(text):
            print 'possible:', p
    elif 'test'.startswith(m):
        test(list(xrange(1, 10)), encrypt, decrypt, hack)
示例#2
0
test_reg = []
test_4k = []
test_9k = []

for i in range(0, 10):
    test_reg.append(
        pandas.read_csv("../../data/y_test_smpl_" + str(i) + ".csv"))
    test_4k.append(pandas.read_csv("../../data/4000_y_test_" + str(i) +
                                   ".csv"))
    test_9k.append(pandas.read_csv("../../data/9000_y_test_" + str(i) +
                                   ".csv"))

# Test model on data set
print("Running test on full dataset")

test(df_X, df_y, df_X_test, df_y_test, model, test_reg)

# Alter dataset by moving 4000 examples from training set to test set
# Adding 4000 instances to a temporary x and y dataframe
# Removing 4000 instances from df_X and df_y
X_train = pandas.read_csv("../../data/4000_x_train_gr_smpl.csv")
X_test = pandas.read_csv("../../data/4000_x_test_gr_smpl.csv")
y_test = pandas.read_csv("../../data/4000_y_test_smpl.csv")
y_train = pandas.read_csv("../../data/4000_y_train_smpl.csv")

print("Running test on 4k dataset")
test(X_train, y_train, X_test, y_test, model, test_4k)

# Adding 9000 instances to a temporary x and y dataframe
# Removing 9000 instances from df_X and df_y
X_train = pandas.read_csv("../../data/9000_x_train_gr_smpl.csv")
示例#3
0
    tick = time.time()
    count = 0
    try:
        while True:
            guess = decrypt(ciphertext, count)
            count += 1
            print 'Possible:', guess
    except:
        tock = time.time()
        time_taken = int(tock - tick)
        print 'Tried %d guesses in %d seconds, that\'s %d per second' % (count, time_taken, count / time_taken)
        years = math.factorial(len(alphabet)) / ((count / time_taken) * 60 * 60 * 24 * 365)
        print 'It would take %d years to brute force this key' % (years,)


if __name__ == '__main__':
    m = raw_input('encrypt/decrypt/hack? ').lower()
    if 'encrypt'.startswith(m):
        text = raw_input('plaintext: ')
        key = int(raw_input('key: '))
        print 'ciphertext:', encrypt(text, key)
    elif 'decrypt'.startswith(m):
        text = raw_input('ciphertext: ')
        key = int(raw_input('key: '))
        print 'plaintext:', decrypt(text, key)
    elif 'hack'.startswith(m):
        text = raw_input('ciphertext: ')
        hack(text)
    elif 'test'.startswith(m):
        test([0, 1000, 2000, 3000, 4000], encrypt, decrypt, hack)