C
C#2y ago
Sebastian

❔ Reversing XOR of shifted numbers

Hello! I have 2 binary numbers: A= 10111 B= 11110 B is A shifted left by 2 positions C is ( A XOR B ) C= 01001 Is it possible to find out A and B by only knowing C ?
11 Replies
ero
ero2y ago
B is not A shifted left by 2
MODiX
MODiX2y ago
Ero#1111
REPL Result: Success
Convert.ToString(0b10111 << 2, 2)
Convert.ToString(0b10111 << 2, 2)
Result: string
1011100
1011100
Compile: 416.632ms | Execution: 22.782ms | React with ❌ to remove this embed.
HimmDawg
HimmDawg2y ago
I'm not too deep in this topic, but I'd say no. Especially if you have a leading 0 like C has.
Sebastian
SebastianOP2y ago
So, to give more context, here is the function that does the shifting, it is in C
void SHL(uchr *c){
char tmp = c[0];

for(int i = 0; i < LEN-1; i++){
c[i] = ((c[i] << 4) & 0xf0 ) | ((c[i+1] & 0xf0) >> 4);
}
c[LEN-1] = ((c[LEN-1] << 4) & 0xf0 ) | ((tmp & 0xf0) >> 4);
}
void SHL(uchr *c){
char tmp = c[0];

for(int i = 0; i < LEN-1; i++){
c[i] = ((c[i] << 4) & 0xf0 ) | ((c[i+1] & 0xf0) >> 4);
}
c[LEN-1] = ((c[LEN-1] << 4) & 0xf0 ) | ((tmp & 0xf0) >> 4);
}
The original values are in hexa and I tried to make it as simple as possible but as it turns out I might not understand it completely. Sorry for that. So a hex number is passed through this function, and the result is XOR-ed with the original number. Will the XOR result be enough to find out the original hex number? I can also post the entire program if you think it helps.
HimmDawg
HimmDawg2y ago
I mean, what you can do is A XOR B = C C XOR A = B C XOR B = A But you cannot create A and B from C out of thin air
Sebastian
SebastianOP2y ago
I understand. I was hoping that knowing the relation between A and B ( B is A shifted) would open the possibility of finding them
ChucklesTheBeard
Yes, there's a 1:1 mapping between A and A^(A<<2) assuming this is shifting and not rotating.
MODiX
MODiX2y ago
ChucklesTheBeard#6079
REPL Result: Success
Dictionary<uint, uint> dict = new();
for (uint A = 0; A <= 0xFF; A++)
{
uint B = A << 2;
uint C = (A ^ B) & 0xFF;
dict.Add(A,C);
}

Console.WriteLine(dict.Values.Distinct().Count());
Dictionary<uint, uint> dict = new();
for (uint A = 0; A <= 0xFF; A++)
{
uint B = A << 2;
uint C = (A ^ B) & 0xFF;
dict.Add(A,C);
}

Console.WriteLine(dict.Values.Distinct().Count());
Console Output
256
256
Compile: 635.129ms | Execution: 51.054ms | React with ❌ to remove this embed.
Sebastian
SebastianOP2y ago
So could this be used to find A and B?
ChucklesTheBeard
Yep, 1:1 mappings are reversible.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server