Question

I am running into a problem. The following program beeps when it runs, which I did not program into it. I am running Windows 7 on a laptop and was wondering why this happens.

My code is basically a simple little encryptor. It is not yet capable of handling things outside of the ASCII range but that is outside the scope of this question.

Ultimately, I would like to know, why does it beep? (Note: this is from a class which is why self is included.)

def encrypt(self,message,private_key):
    import random
    self.message=str(message)
    self.private_key=int(private_key)
    self.public_key=""
    self.final_message=""
    self.errors=[]
    for letter in str(self.message):
        y=random.randrange(0,ord(letter))
        a=y+self.private_key
        x=ord(str(letter))^a
        if x in range(0,256):
            z=chr(x)
            self.final_message=self.final_message+str(z)
            self.public_key=self.public_key+str(chr(y))
        else:
            char="Letter: "+str(letter)+", ASCII value unabled to be processed: "+str(x)+" using keys: "+"Private key: "+str(self.private_key)+" Random Key: "+str(y)
            self.errors.append(char)
    print "Message: "+str(self.message)
    print
    print "Length of Message: "+"["+str(len(str(self.message)))+"]"
    print
    print "Final Message: "+"["+str(self.final_message)+"] "+"length of message: "+str(len(str(self.final_message)))
    print
    print "Public Key: "+"["+str(self.public_key)+"] "+"length of key: "+str(len(str(self.public_key)))
    print
    print "Private Key:"+"["+str(self.private_key)+"]"
    if len(self.errors)!=0:
        print "errors: "
        print
        for error in self.errors:
            print error
            print
Was it helpful?

Solution

http://en.wikipedia.org/wiki/Bell_character

ascii 7 is your culprit. consider encoding into base64 or some other printable subset.

OTHER TIPS

If you are printing ASCII code 7 at any time, you may make your console/terminal beep.

Try it:

>>> print chr(7)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top