To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
Code CritiqueHaving someone critique your code is always a great way to hone the skills. Stop in and post your code to see what your peers may have done differently.
I'm still bored so I made up a ceaser cipher in php.
Here is the function
PHP Code:
function ceaser($clicks,$input) {
//set output to stop errors from showing
$output = "";
//get the length of the string once to aid in efficency
$str_len = strlen($input);
//encryption loop
for($i=0;$i<$str_len;$i++) {
//get the ascii value of the current character
$cur_char = ord(substr($input,$i,1));
//if this is an upper case letter
if($cur_char > 64 && $cur_char < 91) {
//turn the letter into its position in the alphebet
$cur_char = $cur_char - 65;
//move the position according to clicks and turn the position
//back into the value of the ascii letter
$cur_char = ($cur_char + $clicks)%26 + 65;
//if this is a lower case letter
} elseif ($cur_char > 96 && $cur_char < 123) {
//turn the letter into its position in the alphebet
$cur_char = $cur_char - 97;
//move the position according to clicks and turn the position
//back into the value of the ascii letter
$cur_char = ($cur_char + $clicks)%26 + 97;
} //end if
Just incase no clicks specified, it uses rot13 actully.
so people can just do ceaser('bla') for defautt cypher [/b]
Actually since the original Ceaser cipher used 3 clicks then shouldn't I set the clicks to 3 if I'm going to default it?
The reason I didn't default it is because it's more flexible this way. I can define the default clicks in the calling code without changing the function at all.