I am trying to translate some data in one file based on the mappings in another file.
My encryption scheme looks like this:
0 => 129367
1 => 998023
2 => 971513
3 => 365366
4 => 247647
5 => 131747
6 => 86151
7 => 898342
8 => 591121
9 => 828966
a => 185363
b => 420016
c => 472728
d => 185475
e => 669058
f => 472944
g => 932915
h => 109171
i => 940561
j => 483250
k => 240419
l => 158223
m => 494635
n => 205943
o => 19961
p => 989725
q => 125777
r => 195604
s => 818227
t => 83779
u => 990539
v => 639213
w => 669743
x => 546240
y => 950155
z => 631005
A => 126161
B => 403898
C => 323151
D => 536228
E => 653494
F => 810236
G => 808261
H => 900915
I => 60916
J => 417663
K => 371534
L => 384244
M => 900004
N => 300998
O => 346538
P => 5044
Q => 558707
R => 404479
S => 183163
T => 505254
U => 497969
V => 197795
W => 953877
X => 394637
Y => 760236
Z => 211436
! => 601326
" => 15745
# => 428427
$ => 602548
% => 938126
& => 159405
' => 528113
( => 8021
) => 910309
* => 747795
+ => 232242
, => 731593
- => 808534
. => 429705
/ => 916854
: => 241543
; => 755104
< => 314595
= => 398161
> => 606925
? => 804662
@ => 713498
[ => 431477
\ => 80381
] => 36645
^ => 156790
_ => 34787
` => 107682
{ => 283663
| => 650856
} => 91921
~ => 752056
=> 494223
=> 521932
=> 816279
=> 301703
=> 17163
=> 867641
ą => 817209
ś => 594615
ż => 570356
ź => 913303
ł => 752084
ó => 838178
ę => 693877
ń => 564418
ć => 30975
Ż => 707466
My encrypted text looks like:
631005,323151,810236,60916,384244,346538,404479
I tried to replace characters in a loop using the below code:
$my_file = 'encrypted_text.txt';
$handle = fopen($my_file, 'r');
$data = fread($handle,filesize($my_file));
echo "\n".$data."\n";
$file = fopen("encryption_scheme.txt", "r");
$members = array();
while (!feof($file))
{
$code = substr(fgets($file), strrpos(fgets($file), '=> ' )+1);
$code = str_replace('>', '', $code);
$code = str_replace(' ', '', $code);
$letter = substr(fgets($file), 0, 1);
$data = str_replace(',', ' ', $data);
$data = str_replace($code, $letter, $data);
}
echo $data;
fclose($file);
But instead of getting decrypted text it's repeating the codes like
631005,323151,810236,60916,384244,346538,404479
631005 323151 810236 60916 384244 346538 404479
Update
while (!feof($file))
{
$text = fgets($file);
$code = substr($text, strrpos($text, '=> ' )+1);
$code = str_replace('>', '', $code);
$code = str_replace(' ', '', $code);
$letter = substr($text, 0, 1);
$data = str_replace(',', ' ', $data);
$data = str_replace($code, $letter, $data);
}
I am expect a result of z C F I L O R
.