What's new
  • Welcome to PHCorner forums. Take a moment to sign up and gain unlimited access and extra privileges that guests are not entitled to, such as: All that and more! Registration is quick, simple and absolutely free. Join our community today!

Help Creating own enryption phpmysql/js etc..

Pusoy000

Elite
Joined
Jan 30, 2017
Messages
1,541
Reaction
886
Age
22
need idean lang po paano ba gumawa sariling encryption using php..

naguguluhan ako

example: encryption
A = A231
B = A24
C = S32

input: ABC
output: A231A24S32

yun lang sana maymakatulong
 

wally05

Elite
PHP:
<?php
$chars = "abca";
$charArr = str_split($chars); // split natin yung string into chars array
$encArr = array("a"=>"A231", "b"=>"A24", "c"=>"S32"); // key-value dagdagan mo nlng to sundin mo lng yung format..
$hash = "";
foreach($charArr as $c){ // iloop natin laman ng chars array
   foreach($encArr as $key => $val) // key-value pairs
       if($key == $c) $hash .= $val; // check kung magkatugma then iappend natin yung laman ng $val sa $hash
}
echo $hash;
?>
Code:
Output: A231A24S32A231
di ako magaling magexplain kaya intindihin mo nlng..

Pero may masdaling pang paraan dito using str_replace
PHP:
<?php
$string = "abca";
$char = array("a", "b", "c"); // same dapat number ng array sa $enc
$enc = array("A231", "A24", "S32");
$hash = str_replace($char, $enc, $string); // str_replace($from, $to, $string);
echo $string;
?>
Code:
Output: A231A24S32A231

Good Luck!
 
Comment
PHP:
<?php
$chars = "abca";
$charArr = str_split($chars); // split natin yung string into chars array
$encArr = array("a"=>"A231", "b"=>"A24", "c"=>"S32"); // key-value dagdagan mo nlng to sundin mo lng yung format..
$hash = "";
foreach($charArr as $c){ // iloop natin laman ng chars array
   foreach($encArr as $key => $val) // key-value pairs
       if($key == $c) $hash .= $val; // check kung magkatugma then iappend natin yung laman ng $val sa $hash
}
echo $hash;
?>
Code:
Output: A231A24S32A231
di ako magaling magexplain kaya intindihin mo nlng..

Pero may masdaling pang paraan dito using str_replace
PHP:
<?php
$string = "abca";
$char = array("a", "b", "c"); // same dapat number ng array sa $enc
$enc = array("A231", "A24", "S32");
$hash = str_replace($char, $enc, $string); // str_replace($from, $to, $string);
echo $string;
?>
Code:
Output: A231A24S32A231

Good Luck!
Woow

Haha try koyan malaking tulong to pre..

Naiintindiha kona salamat talaga
 
Comment
PHP:
<?php
$chars = "abca";
$charArr = str_split($chars); // split natin yung string into chars array
$encArr = array("a"=>"A231", "b"=>"A24", "c"=>"S32"); // key-value dagdagan mo nlng to sundin mo lng yung format..
$hash = "";
foreach($charArr as $c){ // iloop natin laman ng chars array
   foreach($encArr as $key => $val) // key-value pairs
       if($key == $c) $hash .= $val; // check kung magkatugma then iappend natin yung laman ng $val sa $hash
}
echo $hash;
?>
Code:
Output: A231A24S32A231
di ako magaling magexplain kaya intindihin mo nlng..

Pero may masdaling pang paraan dito using str_replace
PHP:
<?php
$string = "abca";
$char = array("a", "b", "c"); // same dapat number ng array sa $enc
$enc = array("A231", "A24", "S32");
$hash = str_replace($char, $enc, $string); // str_replace($from, $to, $string);
echo $string;
?>
Code:
Output: A231A24S32A231

Good Luck!
Working both code pre? Try koyan mamaya so mag dedeclar nalang ako lahat sa alphabetical at numbers..


Pre kung e dedecrypt ko pano yong logic?
 
Comment

wally05

Elite
Working both code pre? Try koyan mamaya so mag dedeclar nalang ako lahat sa alphabetical at numbers..


Pre kung e dedecrypt ko pano yong logic?
Babaliktarin mo lang yung key-value pairs na array
Ganito sa first method
PHP:
$encArr = array("A231"=>"a", "A24"=>"b", "S32"=>"c");
Sa second method pagbaliktarin mo lng yung laman nung dalawang variable..

EDIT:

May kulang pa palang gagawin paps sa decrypt,
Kaylngan yung encrypt value na iaasign mo sa array of char dapat same ng length ex:
Code:
a = A31
b = ZX1
c = t5J
d = xQu
kase yun gagamitin natin para isplit yung encrypted string para ma decrypt

Decrypt
PHP:
<?php
$chars = "S32A23A24A23A24A23";
$charArr = str_split($chars,3); // split string by 3
$encArr = array("A23"=>"a", "A24"=>"b", "S32"=>"c");
$hash = "";
foreach($charArr as $c){
   foreach($encArr as $key => $val)
       if($key == $c) $hash .= $val;
}
echo $hash;
?>
Code:
Expected Output: cababa
Di ko pa natetest try mo nlng
 
Last edited:
Comment
Babaliktarin mo lang yung key-value pairs na array
Ganito sa first method
PHP:
$encArr = array("A231"=>"a", "A24"=>"b", "S32"=>"c");
Sa second method pagbaliktarin mo lng yung laman nung dalawang variable..

EDIT:

May kulang pa palang gagawin paps sa decrypt,
Kaylngan yung encrypt value na iaasign mo sa array of char dapat same ng length ex:
Code:
a = A31
b = ZX1
c = t5J
d = xQu
kase yun gagamitin natin para isplit yung encrypted string para ma decrypt

Decrypt
PHP:
<?php
$chars = "S32A23A24A23A24A23";
$charArr = str_split($chars,3); // split string by 3
$encArr = array("A23"=>"a", "A24"=>"b", "S32"=>"c");
$hash = "";
foreach($charArr as $c){
   foreach($encArr as $key => $val)
       if($key == $c) $hash .= $val;
}
echo $hash;
?>
Code:
Expected Output: cababa
Di ko pa natetest try mo nlng
ahhh sege2 try ko ngayon paps feedback nalang ako sayo hehe need ko po assistance
 
Comment
Babaliktarin mo lang yung key-value pairs na array
Ganito sa first method
PHP:
$encArr = array("A231"=>"a", "A24"=>"b", "S32"=>"c");
Sa second method pagbaliktarin mo lng yung laman nung dalawang variable..

EDIT:

May kulang pa palang gagawin paps sa decrypt,
Kaylngan yung encrypt value na iaasign mo sa array of char dapat same ng length ex:
Code:
a = A31
b = ZX1
c = t5J
d = xQu
kase yun gagamitin natin para isplit yung encrypted string para ma decrypt

Decrypt
PHP:
<?php
$chars = "S32A23A24A23A24A23";
$charArr = str_split($chars,3); // split string by 3
$encArr = array("A23"=>"a", "A24"=>"b", "S32"=>"c");
$hash = "";
foreach($charArr as $c){
   foreach($encArr as $key => $val)
       if($key == $c) $hash .= $val;
}
echo $hash;
?>
Code:
Expected Output: cababa
Di ko pa natetest try mo nlng


upload_2018-10-31_17-31-54.png
 

Attachments

Comment
Pano mo nilagay ? Pascreenshot
PHP:
<?php

//string that needs to be customized
$rawstring = "roses are red, but some are white too.?";

//placeholders array
$alphabet = array('a', 'b', 'c', 'd','e', 'f', 'g', 'h','i', 'j', 'k', 'l','m', 'n', 'o', 'p','q', 'r', 's', 't','u', 'v', 'w', 'x', 'y', 'z', ' ', '.', ',', '?');
//male replace values array
$enc = array('1', '21', '32', '43', '54', '65', '76', '87', '98', '109', '1110', '1211', '1312', '1413', '1514', '1615', '1716', '1817', '1918', '2019', '2120', '2221', '2322', '2423', '2524', '2625','0', '00', '000', '0000');
//female replace values array
//male string
$malestr = str_replace($alphabet, $enc, $rawstring);


echo $malestr;
//kung mag add ako nito marereplace lahat ewan ko anong problema
//sa alphabet '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
//sa enc a', 'ba', 'cb', 'dc', 'ed', 'fe', 'gf', 'hg', 'ih', 'ji'
?>

gumawa ako ayaw gumana yung binigay mo pre pero malaking tulong yon

ang problema sa code ko , if mag add ako numbers example 0 , 1 to 9 tapos example value sa 0 = A, B= BA;

ang output lahat na rereplace :(
 
Comment

wally05

Elite
PHP:
<?php

//string that needs to be customized
$rawstring = "roses are red, but some are white too.?";

//placeholders array
$alphabet = array('a', 'b', 'c', 'd','e', 'f', 'g', 'h','i', 'j', 'k', 'l','m', 'n', 'o', 'p','q', 'r', 's', 't','u', 'v', 'w', 'x', 'y', 'z', ' ', '.', ',', '?');
//male replace values array
$enc = array('1', '21', '32', '43', '54', '65', '76', '87', '98', '109', '1110', '1211', '1312', '1413', '1514', '1615', '1716', '1817', '1918', '2019', '2120', '2221', '2322', '2423', '2524', '2625','0', '00', '000', '0000');
//female replace values array
//male string
$malestr = str_replace($alphabet, $enc, $rawstring);


echo $malestr;
//kung mag add ako nito marereplace lahat ewan ko anong problema
//sa alphabet '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
//sa enc a', 'ba', 'cb', 'dc', 'ed', 'fe', 'gf', 'hg', 'ih', 'ji'
?>

gumawa ako ayaw gumana yung binigay mo pre pero malaking tulong yon

ang problema sa code ko , if mag add ako numbers example 0 , 1 to 9 tapos example value sa 0 = A, B= BA;

ang output lahat na rereplace :(
Di pwedeng ilalagay mong encryption characters sa $enc ay iba iba ng length dapat magkakamukha
Kunwari 3 lengths lng
123, 2r4, hj7, faj, 00f, ....
kase magiiba na lilitaw output kapag magdecrypt ka
pwede din pala khit iba iba length basta walang kamukha
pag naglagay ka ng single character na "1" dapat sa susunod na characters wala dapat "1" or 0 wala dapat 0 or 23 wala dapat 23 and so on and so fort... ex. (1,23,445,43,99,0,24,32,227,758)
 
Last edited:
Comment

wally05

Elite
Eto oh tried and tested
PHP:
<?php

$string = "roses are red, but some are white too.?";

$alpha = array('a', 'b', 'c', 'd','e', 'f', 'g', 'h','i', 'j', 'k', 'l','m', 'n', 'o', 'p','q', 'r', 's', 't','u', 'v', 'w', 'x', 'y', 'z', ' ', '.', ',', '?', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$val = array('11', '12', '13', '14', '15', '16', '17', '18', '19', '21', '37', '22', '23', '24', '38', '25', '26', '27', '28', '29', '31', '32', '33', '34', '35', '36','00', '10', '20', '30', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48');
$enc = str_replace($alpha, $val, $string);
echo "Encrypted String: " . $enc . "<br/><br/>";

$charArr = str_split($enc, 2);
$dec = "";
foreach($charArr as $ch) $dec .= str_replace($val, $alpha, $ch);
echo "Decrypted String: " . $dec;

output:
Screenshot_2018-10-31-21-15-46.png
 

Attachments

Comment
Eto oh tried and tested
PHP:
<?php

$string = "roses are red, but some are white too.?";

$alpha = array('a', 'b', 'c', 'd','e', 'f', 'g', 'h','i', 'j', 'k', 'l','m', 'n', 'o', 'p','q', 'r', 's', 't','u', 'v', 'w', 'x', 'y', 'z', ' ', '.', ',', '?', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$val = array('11', '12', '13', '14', '15', '16', '17', '18', '19', '21', '37', '22', '23', '24', '38', '25', '26', '27', '28', '29', '31', '32', '33', '34', '35', '36','00', '10', '20', '30', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48');
$enc = str_replace($alpha, $val, $string);
echo "Encrypted String: " . $enc . "<br/><br/>";

$charArr = str_split($enc, 2);
$dec = "";
foreach($charArr as $ch) $dec .= str_replace($val, $alpha, $ch);
echo "Decrypted String: " . $dec;

output:
View attachment 484041
Woooww Idol maraming salamat Po nakuha kona
Nakagawa napala ako design hehe try ko later wala kasi akp laptop..

Matanong lang: dito na portion pag pinalitan ko ng value na 3 Need 3 lengths then sa encryption??

$charArr = str_split($enc, 2); <-
 
Comment

wally05

Elite
Woooww Idol maraming salamat Po nakuha kona
Nakagawa napala ako design hehe try ko later wala kasi akp laptop..

Matanong lang: dito na portion pag pinalitan ko ng value na 3 Need 3 lengths then sa encryption??

$charArr = str_split($enc, 2); <-
Oo paps
 
Comment
patingin ng code mo

gumgana nmn sakin unless may binago ka sa code

tsaka Pag may error sa code mo ilagay mo na din screenshot ng code mo para ichecheck ko nlng kung ano mali..


Try ko yong code mo ganyan talaga lumalabas pati yong unang code na binigay mo idol
 
Comment

wally05

Elite
tignan mo mabuti yung code mo dun sa line 3
sa
$string = "roses are red, but some are white too.?";
Mali Ka ng Kopya tignan mo maigi yung line na yan sa code mo may nilagay ka atang Single Quote '
yan kase ibigsabihin ng T_CONSTANT_UNCAPSE_STRING
Invalid yung gantong quoting sa string variable
PHP:
$inv = 'this is invalid";

$inv = "this is invalid';

$inv = 'this 'is invalid";


kaya nga pinascreenshot ko sayo yung code mo para mahanap ko nagcacause ng error
 
Last edited:
Comment
tignan mo mabuti yung code mo dun sa line 3
sa
$string = "roses are red, but some are white too.?";
Mali Ka ng Kopya tignan mo maigi yung line na yan sa code mo may nilagay ka atang Single Quote '
yan kase ibigsabihin ng T_CONSTANT_UNCAPSE_STRING
Invalid yung gantong quoting sa string variable
PHP:
$inv = 'this is invalid";

$inv = "this is invalid';

$inv = 'this 'is invalid";


kaya nga pinascreenshot ko sayo yung code mo para mahanap ko nagcacause ng error
ganyan parin yong error pinalitan konayan idol

eto yong code ohh
pa fix nga :( parang basic mistake lang ata to diko makuha

PHP:
$string = "roses are red, but some are white too.?";

$alpha = array('a', 'b', 'c', 'd','e', 'f', 'g', 'h','i', 'j', 'k', 'l','m', 'n', 'o', 'p','q', 'r', 's', 't','u', 'v', 'w', 'x', 'y', 'z', ' ', '.', ',', '?', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$val = array('11', '12', '13', '14', '15', '16', '17', '18', '19', '21', '37', '22', '23', '24', '38', '25', '26', '27', '28', '29', '31', '32', '33', '34', '35', '36','00', '10', '20', '30', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48');
$enc = str_replace($alpha, $val, $string);
echo "Encrypted String: " . $enc . "<br/><br/>";

$charArr = str_split($enc, 2);
$dec = "";
foreach($charArr as $ch) $dec .= str_replace($val, $alpha, $ch);
echo "Decrypted String: " . $dec;
<?php
    
$string = "hindi talaga gumagana ganun parin";

$alpha = array('a', 'b', 'c', 'd','e', 'f', 'g', 'h','i', 'j', 'k', 'l','m', 'n', 'o', 'p','q', 'r', 's', 't','u', 'v', 'w', 'x', 'y', 'z', ' ', '.', ',', '?', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$val = array('11', '12', '13', '14', '15', '16', '17', '18', '19', '21', '37', '22', '23', '24', '38', '25', '26', '27', '28', '29', '31', '32', '33', '34', '35', '36','00', '10', '20', '30', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48');
$enc = str_replace($alpha, $val, $string);
echo "Encrypted String: " . $enc . "<br/><br/>";

$charArr = str_split($enc, 2);
$dec = "";
foreach($charArr as $ch) $dec .= str_replace($val, $alpha, $ch);
echo "Decrypted String: " . $dec;


?>
 
Comment

Online statistics

Members online
1,104
Guests online
1,595
Total visitors
2,699

Forum statistics

Threads
1,069,444
Messages
18,092,736
Members
1,515,103
Comments
1,068,469
Attachments
1,383,008
Profile posts
97,554
Top