Hello.
I'm making a XOR based decryptor, that works like this.
you have a character, fx 3, and a user key, fx 5
in bits:
3 = 00000011
5 = 00000101
-- Now if we do XOR operation, we get 6
6 = 00000110
-- This can be reversed by saying 6 XOR 5, which is 3
...
So I have made this program, but its really buggy, and adds a lot of characters in the end of the file (depeding which key you are using).
Line 15 should just be while(!fin.eof()) at the end of the file there's nothing left to do anyway so why does it matter if znak has a value?
In your function you're comparing an integer key with what should be a char key. Integer numbers and Char numbers have different values believe it or not.
#computergeek01
Yeah, the line 15 was a mistake. It was only while(!fin.eof()) , but since it didn't work, I tried other ways.
In my function I'm comparing integer to character, but does it matter? It should work anyway, right?
It would be possible, but a mathmatical process is only reversable if the values are the same. You have to change three lines of code to test out my suggestion. If it doesn't work then put them right back. What do you have to lose?
My post will not help with the problem you're asking about, however it does have some good advice that is somewhat relevant.
1 2 3 4 5 6 7 8 9 10 11 12 13
char function(int key,char input)
{
int intChar = input; // you already have 'input', why copy to another variable?
// why not just use 'input' directly?
// furthermore, why promote to an int? it makes no sense here
char encryptedChar = NULL; // why initialize it with null...
encryptedChar = intChar ^ key; // ...only to reassign it right away?
// why not just initialize it with what you want?
return encryptedChar; // if you're just returning it anyway, why bother with a variable at all?
}
#Disch
I know my code is very messy, because I edit in it all the time.
In the function, I assign input to intChar, because Computergeek01 said that I have to use two integers, not one integer and one character. (Look above in the comments)
If I left you with the impression that you have to use two integers then I apoligize I only meant to say that the data types have to be the same. You could use two chars, and I think you'd be better off that way anyway.