Jump to content

Python - need help with 'chr' built in function

 

So I have this keylogger which is supposed to take the event.Ascii value which is an integer and translate that into a character by using the chr function and then write it into a file. Well it's writing the file but not as I expect, I'm getting these weird symbols instead... you can see the output below:

PS I've simplified the code for viewing / testing purposes, I took out the file read / write part to narrow down the problem.

Code: http://ideone.com/OrXK6E

My output: http://imgur.com/fdD0W3S

Thanks!

 

Link to comment
https://linustechtips.com/topic/579481-python-need-help-with-chr-built-in-function/
Share on other sites

Link to post
Share on other sites

Probably a translation error, the integer should be the decimal that correlates with the hex character, e.g.,

 

>>> letter
'A'
>>> ord(letter)
65
>>> chr(65)
'A'

 

so if the ints you're running chr() on aren't in the range of 65-125, then that's probably why

Link to post
Share on other sites

28 minutes ago, transposedmessenger said:

Probably a translation error, the integer should be the decimal that correlates with the hex character, e.g.,

 

>>> letter
'A'
>>> ord(letter)
65
>>> chr(65)
'A'

 

so if the ints you're running chr() on aren't in the range of 65-125, then that's probably why

Yeah that makes sense, but why wouldn't my keyboard input produce an integer value between 65-125, I mean realistically it should since were basically translating it from its Ascii input to it's corresponding character.

Link to post
Share on other sites

1 hour ago, transposedmessenger said:

Probably a translation error, the integer should be the decimal that correlates with the hex character, e.g.,

 

>>> letter
'A'
>>> ord(letter)
65
>>> chr(65)
'A'

 

so if the ints you're running chr() on aren't in the range of 65-125, then that's probably why

OK, after further testing it turns out you're right, my Ascii values are not correct for some reason and they do not fall in between the 65-125 range... do you have any idea why this might be?

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×