p____h Just Arrived
Joined: 13 May 2010 Posts: 0 Location: Poland
|
Posted: Thu May 13, 2010 1:03 pm Post subject: |
|
|
I’ll just try to give You a few hints.
Let’s look at Your code:
Code: |
function f($i)
echo base64_encode(chr(8).chr($i)); |
It can’t work at all, because it generates the same pattern:
Quote: |
f(0): CAA=
f(1): CAE=
f(2): CAI=
…
f(256): CAA=
f(257): CAE=
f(258): CAI=
|
See the pattern now?
That chars are repeated.
f(x)=f(x+256)
because we don’t wanna get the same results for f(x+256) to encoded string we must ‘add’ the fourth char.
Just look at the first char of the string, it’s always C.
The second char is A, B, C, D, E, F, G, H, I, J, K, L, M, N, O or P
Look at the third chars of generated strings: A, E, I, M, Q, U, Y, c, g, k, o, s, w, 0, 4, 8
Let’s try to find out, what the fourth char could be.
We have to analyze Your example.
CJ4 – 158 (as Your algorithm says)
Please, notice, that:
Quote: |
CJ4d - 3742=158+16*224
COkH - 1001=233+16*48
CM0g - 4173=205+16*248
CM03 - 7117=205+16*432
CJof - 3994=154+16*240
CNwE - 604=220+16*24
CMQP - 1988=196+16*112
CJsi - 4379=155+16*264
CO0i - 4461=237+16*264
CPAm - 4976=240+16*296
CKsE - 555=171+16*24
CK8f - 4015=175+16*240
COch - 4327=231+16*256
CIAW - 2816=128+16*168
CJ0U - 2589=157+16*152
CNIq - 5458=210+16*328
CNkR - 2265=217+16*128
CI4F - 654=142+16*32
|
So if we have to decode string like ABCD, we have to decode string ABC and ‘add’ number to the output.
Let’s look at the example:
Quote: |
CKs– 8 171
CKsE – 8 171 4
CKsF – 8 171 5
CKsG – 8 171 6
…
CKs9 – 8 171 61
CKs+ - 8 171 62
CKs/ - 8 171 63
CKtA - 8 171 64
|
As I said, the first char is always ‘C’, than, there are 16 chars which can go on the second place, and the same amount of chars which can go to the third place. On the fourth place we can put one of the 64 chars.
Moreover:
Quote: |
CKsE – 8 171 4
CJoE – 8 154 4
CAoE – 8 10 4
|
etc (look at the fourth char, it’s the same)
OK, let’s look at the examples again.
CJ4d - 3742=158+3584, ‘cos CJ4 is 158
COkH - 1001=233+768, ‘cos COk is 233
etc.
We know, that 3584 and 768 define the fourth char.
I’ll show you something on that two examples:
Code: |
CJ4d - 3742=158+3584
MOD(3584; 63)=56
CJ4d - 8 158 29
29 - MOD(56; 29)=2
|
Code: |
COkH - 1001=233+768
MOD(768; 63)=12
COkH - 8 233 7
7 - MOD(12; 7)=2
|
And it’ll be almost always 2
Code: |
ABCD – 8 X Y
ABCD – X + Z
MOD(Z;63)=W
Y-MOD(W; Y)=2
|
it’s true when W>Y
Hope, that this simple observation will help you.
|
|
vdeny Just Arrived
Joined: 01 May 2010 Posts: 0
|
Posted: Thu May 13, 2010 5:16 pm Post subject: |
|
|
Thank you very much p____h, for your reply with analysis! I will study your reply and hope it will help me.
I've made a couple of days ago algorithm which correctly converts 1st, 3nd, and 4th characters. I still have problem with 2nd character:
Code: |
<?php
$i=0;
$num = 4015; //correct code is CK8f
while ($num>0)
{
$arr[$i]=$num%128;
$num=(int)($num/128);
echo "\$arr[".$i."]=".$arr[$i]."; \$num =".$num."</br>";
$i++;
}
echo base64_encode(chr(8).chr($arr[0]).chr($arr[1])); //CC8f. Second character doesn’t match. 1st,3rd and 4th characters are matched with the correct code CK8f.
?>
|
[/b]
|
|