Jump to content

Search the Community

Showing results for tags 'cipher'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. 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.