|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Cryptogram
Okay...my girlfriend likes doing cryptograms so I thought it would be a good chance to work on some string manipulation if I made her a dynamic web app to do these. Eventually it is going to pull quotes from a database so that I won't have to enter in a new one all the time. I'm having a little trouble with the algorithms to shuffle the quote around on a index alphabet. Hopefully the code will help it make more sense. I think that I am close but it isn't encoding the quote completely correctly yet if you see the out put of the code.
[CODE] <? $str1 = "As you can clearly see from this image, without salsa, Leonard Nimoy's projected level of excellence is not even controllable! However, as we suspected, with the benefit of salsa, Leonard Nimoy's level of excellence will be unstoppable!"; //$str1Arrary[] = array(); //for ($i = 0; $i < count($str1); $i++) //{ //$str1Array[$i] = $str1[$i]; //} $str1 = strtolower($str1); echo $str1; echo '<br />'; echo '<br />'; $beta = 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"); $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"); //shuffles the alphabet for($j = 0; $j < count($alpha); $j++) { $num = rand(0, 25); $temp = $alpha[$j]; $alpha[$j] = $alpha[$num]; $alpha[$num] = $temp; } //displays the shuffled alphabet for($k = 0; $k < count($alpha); $k++) { echo $alpha[$k]; } echo '<br />'; echo '<br />'; for($w = 0; $w < strlen($str1); $w++) { for($z = 0; $z < count($alpha); $z++) { if ($str1[$w] == $alpha[$z]) { $str1[$w] = $beta[$z]; } } } for($s = 0; $s < strlen($str1); $s++) { echo $str1[$s]; } ?> |
|
#2
|
|||
|
|||
|
RE: Cryptogram
i'm not to familiar with cryptograph's.. are you just shuffling words around or the letters of the words around? what is it supposed to do?
|
|
#3
|
|||
|
|||
|
RE: Cryptogram
In cryptograms letters are given different values. ie. shuffles the alphabet
(PHP is fun) ===> (XMX hq jop) then the person has to decode a phrase |
|
#4
|
|||
|
|||
|
RE: Cryptogram
ohh cool
edit: new code below it works okay but replaces comma's and stuff with letters too but i'm off work which means i'm not staying late to finish |
|
#5
|
|||
|
|||
|
RE: Cryptogram
sounds good. Thanks for you help. For some reason the way I was doing it worked fine as long as the word didn't have 2 of the same letters in it.
|
|
#6
|
|||
|
|||
|
RE: Cryptogram
PS- Where is Creve Coeur, IL?
I'm from Arlington Heights, IL |
|
#7
|
|||||
|
|||||
|
RE: Cryptogram
alright the following code will work with comma's, apostrophies or whatever
php Code:
|
|
#8
|
|||
|
|||
|
RE: Cryptogram
I see I see. You've probably heard of Arlington Heights because of the horse track...that is why most people recognize
|
|
#9
|
|||||
|
|||||
|
RE: Cryptogram
ResNet9:
Here's what I think you are looking for. This code will create a valid cryptogram and keep the letter case intact. The problem with Notepad's code is that while it does to the letter substitution, your girlfriend will be very frustrated since 'a' may mean 'b' in one place and mean 'q' or 'c' some other place. For a cryptogram to be solvable, it needs to have consistent substitutions. php Code:
Anyway, I hope this helps. The ArrayShuffle routine is in there since I found that PHP's shuffle function doesn't work very well. The ArrayShuffle function seems to work much better, and you should get a different cryptogram for the phrase every time you reload. Dave |
|
#10
|
|||
|
|||
|
RE: Cryptogram
ahh.. see i didn't know any better
|
|
#11
|
|||
|
|||
|
RE: Cryptogram
Not a problem notepad. I figured that's all the problem was.
Dave |