Jump to content

Canaan

New Members
  • Posts

    4
  • Joined

  • Last visited

Canaan's Achievements

Newbie

Newbie (1/5)

0

Reputation

1

Community Answers

  1. yeah thanks for the help I've only been using PHP for like a month so i'm just testing what i can do not for real use i know that it would be much more secure to use a hash but i just found it interesting and i'm not really sure substr as I've only learned the basics and pretty much stumbled on the idea but it was more the thought of a procedural number but i just found it an interesting idea thanks for the quick responses.
  2. Hi, all I'm new here so not sure if i'm doing this right but i was hoping to create my own form of PHP based encryption function. I'm sure there are already functions out there but i wanted to see if this was something i could do personally. So my situation is i have used the str_replace function to change the inputted letters to numbers then explode the string to an array. Then I add on however many in the alphabet i would like to move the inputted string down the alphabet by then this array is simply imploded and re-written back into the alphabet. This issue i have is as some might have already realized yet i find it hard to explain so i have to give an example, so say i have abcdefgh and i want to move it down 4 this would first turn into 1,2,3,4,5,6,7,8 then i would add on 4 to each number so this would make 5,6,7,8,9,10,11,12 then as i try to change this back to letters anything above 9 is read as separate number so i would get this changed back to e,f,g,h,i,a,0,a,a,a,b. I know that it recognizes the double digit numbers as two separate numbers but i'm not sure how i could get past this. below is the code and yes before anyone says it, i' m sure there's an easier way but i only clear up my code once i get the outcome i want. Thank-you for reading this, Canaan. <?php function encrypt($string, $multiplyer) { $string = preg_replace('/\s+/', '', $string); $legnthofstring = strlen($string); $string = strtolower($string); $string = str_replace("a","1",$string); $string = str_replace("b","2",$string); $string = str_replace("c","3",$string); $string = str_replace("d","4",$string); $string = str_replace("e","5",$string); $string = str_replace("f","6",$string); $string = str_replace("g","7",$string); $string = str_replace("h","8",$string); $string = str_replace("i","9",$string); $string = str_replace("j","10",$string); $string = str_replace("k","11",$string); $string = str_replace("l","12",$string); $string = str_replace("m","13",$string); $string = str_replace("n","14",$string); $string = str_replace("o","15",$string); $string = str_replace("p","16",$string); $string = str_replace("q","17",$string); $string = str_replace("r","18",$string); $string = str_replace("s","19",$string); $string = str_replace("t","20",$string); $string = str_replace("u","21",$string); $string = str_replace("v","22",$string); $string = str_replace("w","23",$string); $string = str_replace("x","24",$string); $string = str_replace("y","25",$string); $string = str_replace("z","26",$string); $arr1 = str_split($string); $counter = 0; $los=$legnthofstring; while($counter < $los) { $arr1[$counter] += $multiplyer; $counter ++; } $tring = implode(",", $arr1); echo($tring); echo"<p>"; $tring = str_replace("1","a",$tring); $tring = str_replace("2","b",$tring); $tring = str_replace("3","c",$tring); $tring = str_replace("4","d",$tring); $tring = str_replace("5","e",$tring); $tring = str_replace("6","f",$tring); $tring = str_replace("7","g",$tring); $tring = str_replace("8","h",$tring); $tring = str_replace("9","i",$tring); $tring = str_replace("10","j",$tring); $tring = str_replace("11","k",$tring); $tring = str_replace("12","l",$tring); $tring = str_replace("13","m",$tring); $tring = str_replace("14","n",$tring); $tring = str_replace("15","o",$tring); $tring = str_replace("16","p",$tring); $tring = str_replace("17","q",$tring); $tring = str_replace("18","r",$tring); $tring = str_replace("19","s",$tring); $tring = str_replace("20","t",$tring); $tring = str_replace("21","u",$tring); $tring = str_replace("22","v",$tring); $tring = str_replace("23","w",$tring); $tring = str_replace("24","x",$tring); $tring = str_replace("25","y",$tring); $tring = str_replace("26","z",$tring); echo $tring; } encrypt("abcdefg",3);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.