- #36
PeterDonis
Mentor
- 47,552
- 23,825
Then you are using the wrong operation. You don't want to convert an integer to a string. You want to convert a string (the message) into an integer (or a sequence of integers).Arman777 said:I meant this
You are very confused.Arman777 said:In my previous post, I was trying to say that you'll need a lot of storage if you store the key as binary. But an ASCII key will be more useful in terms of storage.
First, as I have already pointed out, "binary" is not a Python data type. What you are calling "binary" are Python strings that contain "0" and "1" characters that can be interpreted as the bits in a binary representation of an integer, but that does not mean you should actually use this for any kind of arithmetical or logical operation. That's not what the bin() function is for.
You say this bin() conversion is an intermediate step, but I don't think you've fully thought through what you are doing. If you already have an integer representing a character in the message and an integer representing a character in the key, you can just xor them directly in Python. There is no need to convert them into these "binary" strings.
Yes, and this is a 64-bit integer. It's not a string of 64 bytes that are either "0" or "1".Arman777 said:If your message is "password," and if you want to make the XOR encryption "unbreakable," you need to create a random binary key that is 64 bits long.
First, most of those characters aren't ASCII characters, so the term "ASCII" is incorrect.Arman777 said:For instace, I have generated a random binary key. So for an unbreakable message you'll need to store this.
0000110011010000111111100100101110110010010011110110110000101011
but if you convert this into ASCII (or as ASCII key), you'll need to store just
♀ÐþK²Ol+
Second, since what you have is a 64-bit integer, you should just represent it as a Python integer and do Python operations on it directly as an integer.
The "unprintable" characters aren't ASCII characters to begin with, as noted above. But more important, viewing them as "characters" makes no sense. As above, you have a 64-bit integer. You can represent integers directly in Python as integers.Arman777 said:Here, the only problem is that the binary representation of the key can also represent the unprintable ASCII characters.
Exactly! Except that there is no need for the bin() function anywhere. You have an integer; if you want to convert it to a character, you call ord() on it, not bin().Arman777 said:Instead of turning 67 and 45 into bytes and then doing XOR bitwise I could have just do
bin(67 ^ 45)
which gives the correct answer. This approach will definately shorten my code
What are you talking about? You just did understand it (in what I quoted above and responded to with "Exactly!").Arman777 said:You guys are giving hints but I cannot understand something that i don't know...
What? Why are you throwing away the right answer right after you found it?Arman777 said:Hex is a good approach