Jump to content

winthropite

New Members
  • Posts

    5
  • Joined

  • Last visited

winthropite's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm telling you what the problem with the code is and what I've tried to fix it. I've never heard of ctype alpha. I have been learning PHP for maybe 3 months now, 2 days a week. My feet are barely wet. I thought I showed how I did try myself but that's not enough. I've spent probably 20 hours messing with this code to get it to work right. Who the hell are you to assume I'm lazy or lying? I expected help here but instead got hard-headedness now from you and outright rudeness from Kevin in the way he smugly made an assumption that was completely wrong instead of asking first. And now you assuming laziness or lies. Well, we all know what people who assume are, don't we? There are a number of other similar forums where the members actually help and share code snippets to people in need. No assumptions, no rudeness, just people who understand that writing a bit of code to help out people who have already tried everything they can to get their code to work isn't perpetuating laziness; it's just common decency. I'll figure this out on my own. I'd rather rewrite the code another 20 hours than continue to deal with the nasty, elitist attitudes here.
  2. I did write it. I also tried multiple solutions, such as <?php
 $string = $_POST['msg']; 
$newstring = $string; 
$sp = $_POST['offset']; 

for ($i=0; $i < strlen($string); $i++) { $ascii = ord($string[$i]); for ($j=0; $j < $sp; $j++) { if ($ascii == 90) { //uppercase bound
 $ascii = 65; //reset back to 'A' } else if ($ascii == 122) { //lowercase bound $ascii = 97; //reset back to 'a' } else if ( ($ascii >= 65 && $ascii <= 90) || ($ascii >= 97 || $ascii <= 122 ) ) { $ascii++; }
 }
 $newstring[$i] = chr($ascii); $encstring = $newstring;
}
?> and <?php $sp = $_POST['offset']; $string = $_POST['msg']; $newstring = array(); for ($i=0; $i < strlen($string); $i++) { $ascii = ord($string[$i]); if ($ascii < 65 || ($ascii > 90 && $ascii < 97) || $ascii > 122) { $newstring[$i] = $string[$i]; } else { for ($j=0; $j < $sp; $j++) { $ascii += 1; if ($ascii == 91 || $ascii == 123) { $ascii -= 26; } } $newstring[$i] = chr($ascii); } } $encstring = implode('', $newstring); echo $encstring; I'm honestly just looking for a hand. I'm new to PHP and am simply asking for help.
  3. Yes, it was. And I have code that works; I was the only student who did. I was also the only one who put the code into a fully responsive site. I passed the homework with flying colors. But far be it to assume you know the details; the class project is long over. I'd be glad to send you my instructor's email for confirmation. I'm finishing this for myself. So, that being said, is it possible to get a hand with this?
  4. @.josh, thanks for your reply. Unfortunately, I'm not well enough acquainted with PHP to understand what that means. Would it be bad karma to ask that the specific code that will make it work be posted?
  5. Hey everyone, I wrote a Caesar cipher (a script where, given a message, the letters in the message are shifted x number of places; e.g. A => D, B => E, C => F, X => A, Y => B, Z => C, etc.). It works but it shifts all ASCII characters. I want to exclude characters that are not A-Z or a-z (outside the ASCII values of 65 - 90 and/or 97 - 122) so that spaces, punctuation, numbers all remain the same instead of shifting as well. Here's the form on index.html <form class="form-inline" role="form" method="post"> <div class="table-responsive"> <table> <tr class="tr_top"> <td class="td_top"><textarea class="form-control" rows="4" name="msg" placeholder="Your message here." onfocus='this.select()'><?php require ('encode.php'); require ('decode.php'); if (isset($_POST['encode'])) { echo $encstring; } elseif (isset($_POST['decode'])) { echo $decstring; } ?></textarea></td> </tr> <tr class="tr_mid"> <td class="td_mid"><input type=text class="form-control input_mid" name="offset" value="<?php if (isset($_POST['encode']) || isset($_POST['decode'])) { echo htmlspecialchars($_POST['offset']);} ?>" placeholder="Enter a number." pattern="[0-9]{0,3}" oninvalid="setCustomValidity('Please enter a number between 1 and 999.')" oninput="setCustomValidity('')"></td> </tr> <tr class="tr_bottom"> <td class="td_bottom"> <input class="input_bottom btn btn-default submit" type="submit" name="encode" value="Encode"> <input class="input_bottom btn btn-default submit" type="submit" name="decode" value="Decode"> <input class="input_bottom btn btn-default" type="button" value="Clear"</td> </tr> </table> </div><!-- close table-responsive --> </form> <?php //encode require ('encode.php'); if (isset($_POST['encode'])) { echo "<p>Original message:</p>"; echo "<p class='string ital'>" . $string . "</p>"; echo "<p>Encoded message:</p>"; echo "<p class='string ital'>" . $newstring . "</p>"; } //decode require ('decode.php'); if (isset($_POST['decode'])) { echo "<p>Encoded message:</p>"; echo "<p class='string ital'>" . $string . "</p>"; echo "<p>Decoded message:</p>"; echo "<p class='string ital'>" . $newstring . "</p>"; } ?> and here is encode.php <?php $string = $_POST['msg']; $newstring = $string; $sp = $_POST['offset']; for ($i=0; $i < strlen($string); $i++) { $ascii = ord($string[$i]); for ($j=0; $j < $sp; $j++) { if ($ascii == 90) { //uppercase bound $ascii = 65; //reset back to 'A' } else if ($ascii == 122) { //lowercase bound $ascii = 97; //reset back to 'a' } else { $ascii++; } } $newstring[$i] = chr($ascii); $encstring = $newstring; } ?> Any help would be appreciated as I can't figure it out. If you want to see it in action it's here.
×
×
  • 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.