• RSS
  • Twitter
  • FaceBook

Security Forums

Log in

FAQ | Search | Usergroups | Profile | Register | RSS | Posting Guidelines | Recent Posts

How to decrypt/encrypt? (numbers to xxxx and vise versa)

Users browsing this topic:0 Security Fans, 0 Stealth Security Fans
Registered Security Fans: None
Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Cryptographic Theory and Cryptanalysis - Internal and Transmission Security

View previous topic :: View next topic  
Author Message
vdeny
Just Arrived
Just Arrived


Joined: 01 May 2010
Posts: 0


Offline

PostPosted: Sat May 01, 2010 6:59 pm    Post subject: How to decrypt/encrypt? (numbers to xxxx and vise versa) Reply with quote

I have some pairs of numbers and their codes (xxx= and xxxx) and I've found a way to decrypt/encrypt xxx=
Here are the examples:
"CDI=" - 50
"CFc=" - 87
"CDw=" - 60

The xxx= codes can be decrypted/encrypted with the following code in PHP:
//Encrypt:
$int=87;
echo base64_encode(chr(8).chr($int)); //CFc=

// Decrypt:
$a=base64_decode("CFc=");
echo ord($a{1}); //87

However this code doesn't decrypt/encrypt codes like xxxx
Can anybody help to decrypt/encrypt codes into numbers and vise versa for xxxx?

Here are all pairs of number/codes xxxx pairs which I have:
CJ4d - 3742
COkH - 1001
CM0g - 4173
CM03 - 7117
CJof - 3994
CNwE - 604
CMQP - 1988
CJsi - 4379
CO0i - 4461
CPAm - 4976
CKsE - 555
CK8f - 4015
COch - 4327
CIAW - 2816
CJ0U - 2589
CNIq - 5458
CNkR - 2265
CI4F - 654
Back to top
View user's profile Send private message
p____h
Just Arrived
Just Arrived


Joined: 13 May 2010
Posts: 0
Location: Poland

Offline

PostPosted: Thu May 13, 2010 1:03 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
vdeny
Just Arrived
Just Arrived


Joined: 01 May 2010
Posts: 0


Offline

PostPosted: Thu May 13, 2010 5:16 pm    Post subject: Reply with quote

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]
Back to top
View user's profile Send private message
vdeny
Just Arrived
Just Arrived


Joined: 01 May 2010
Posts: 0


Offline

PostPosted: Mon May 17, 2010 12:11 am    Post subject: Reply with quote

Thank you again, p____h! Your reply helped me to make working version of conversion. Here is the working peace of code:
Code:

<?php

$i=0;
$num = 1988;
$num = $num.'';
$saved_num = $num;
echo "Encoding ID: ".$num."</br>";

while ($num>0)
{
  $arr[$i]=$num%128;
  $num=(int)($num/128);
  echo  "\$arr[".$i."]=".$arr[$i]."; \$num =".$num."</br>";
  $i++;
}

$first_char = 8;
$third_char = $arr[1];
$second_char = $saved_num - (($third_char*2)-2)*64;

echo "Code: ".base64_encode(chr($first_char).chr($second_char).chr($third_char))."</br>";

?>
Back to top
View user's profile Send private message
Display posts from previous:   

Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Cryptographic Theory and Cryptanalysis - Internal and Transmission Security All times are GMT + 2 Hours
Page 1 of 1


 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Community Area

Log in | Register