Marco C
Marco C

Reputation: 95

binascii unsupported operand type(s) for /: 'str' and 'int'

I'm a beginner, sorry is this is obvious or weird. I also apologize if this has been answered before, I just can't find anything that really works.

I'm trying to make a program to encrypt and decrypt text files.

My thinking behind this is to encrypt the characters into number forms, and multiply them as the encryption, and of course divide as the decryption.

The Encryption part works perfectly, but when running the decryption code I keep getting a

unsupported operand type(s) for /: 'str' and 'int'.

I've tried float and int, but they don't work.

Encryption Code:

import binascii

#ENCRYPTION ALGORITHM
algorithm = 2

#ASCII ----> NUMBERS
raw = raw_input("Enter text to encrypt:")
one = binascii.hexlify(raw)
two = binascii.hexlify(one)

#UNENCRYPTED HEX
unencrypted = int(two)

#ENCRYPT HEX
encrypted =  unencrypted * algorithm

#PRINTS ENCRYPTED TEXT
print "%.9f" % encrypted

Decryption Code:

import time
import binascii

incorrectpasswords = 0
password=("mypass")
originpassword = password
x = 1
algorithm = 2

while x==1:
    passwordattempt =raw_input("Enter Password:")
    if passwordattempt == password:
        print("Correct")
        x = 2

    if passwordattempt!= password:
        print("Incorrect")
        incorrectpasswords = incorrectpasswords + 1
    if incorrectpasswords > 2:
        if x == 1:
            password = (generatedpassword)
            print("Too many wrong attempts, please try again in one minute.")
            time.sleep(60)
            password=originpassword


encrypted = float(input("Enter text to unencrypt:"))
formatted = "%.9f" % encrypted
formatted2 = formatted
one = formatted2 / algorithm
print ("%.9f" % one)
two = binascii.unhexlify(one)
unencrypted = binascii.unhexlify(two)
print(unencrypted)

Also, this in python 2.7 as binascii isn't working for me in python 3.

Upvotes: 1

Views: 174

Answers (1)

OneCricketeer
OneCricketeer

Reputation: 191738

You shouldn't try to divide a formatted string by a number.

algorithm = 2

encrypted = float(input("Enter text to unencrypt:"))
one = encrypted / algorithm
print("%.9f" % one)

Upvotes: 0

Related Questions