Thursday, August 21, 2014

Alphabet to numbers + CODE

Put this on your page to encode, scramble, and decode strings! It's amazing! :D

Usage

When using this, you must give credit, as this is under a Creative Commons License (see sidebar for more information)

Notes

  1. Does not retain capitalization or punctuation
  2. Spaces are replaced with a '<space>' Sub-string after the initial encoding. You would have to replace this manually if you don't like it.

Try it out!

String:

Offset:

Code

  1. /*
  2.         ccccc ooooo dddd   eeeee
  3.         C     O   O D   D  E
  4.         C     O   O D    D Eee
  5.         C     O   O D   D  E
  6.         ccccc ooooo dddd   eeeee
  7.        
  8.         Copyright 2014 Conor O'Brien under a Creative Commons Attribution 4.0 International License.
  9. */
  10. var alphabet = {
  11.         lower: ["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"],
  12.         upper: ["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"],
  13.         number: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]
  14. }
  15. String.prototype.encode = function(){
  16.         var str = this.valueOf();
  17.         var returnStr = [];
  18.         var notAny = false;
  19.         str = str.toLowerCase()
  20.         str = str.split("")
  21.         for(i = 0; i < str.length; i++){
  22.                 for(h = 0; h < alphabet.lower.length; h++){
  23.                         if(str[i]==alphabet.lower[h]){                 
  24.                                 returnStr.push(h+1)
  25.                         } else {
  26.                                 notAny = true;
  27.                         }
  28.                 }
  29.                 if(str[i]==" "){
  30.                         returnStr.push("<space>")
  31.                 } else if(!notAny){
  32.                         returnStr.push(str[i])
  33.                 }
  34.                 notAny = false;
  35.         }
  36.         returnStr = returnStr.toString();
  37.         while (returnStr.search(",") !== -1){
  38.                 returnStr = returnStr.replace(","," ");
  39.         }
  40.         return returnStr;
  41. }
  42.  
  43. String.prototype.scramble = function(number){
  44.         var str = this.valueOf();
  45.         var returnStr = [];
  46.         var notAny = false;
  47.         str = str.toLowerCase()
  48.         str = str.split(" ")
  49.         for(i = 0; i < str.length; i++){
  50.                 for(h = 0; h < alphabet.number.length; h++){
  51.                         if(str[i]==alphabet.number[h]){                
  52.                                 returnStr.push(alphabet.number[h] + number)
  53.                         }
  54.                 }
  55.         }
  56.         returnStr = returnStr.toString();
  57.         while (returnStr.search(",") !== -1){
  58.                 returnStr = returnStr.replace(","," ");
  59.         }
  60.         return returnStr;
  61.        
  62. }
  63. String.prototype.decode = function(){
  64.         var str = this.valueOf();
  65.         var returnStr = [];
  66.         str = str.toLowerCase()
  67.         str = str.split(" ")
  68.         for(i = 0; i < str.length; i++){
  69.                 for(h = 0; h < alphabet.number.length; h++){
  70.                         if(str[i]==alphabet.number[h]){                
  71.                                 returnStr.push(alphabet.lower[h])
  72.                         }
  73.                 }
  74.                 if (str[i]=="<space>"){
  75.                         returnStr.push(" ");
  76.                 }
  77.         }
  78.         returnStr = returnStr.toString();
  79.         while (returnStr.search(",") !== -1){
  80.                 returnStr = returnStr.replace(",","");
  81.         }
  82.         return returnStr;
  83. }
  84.  

2 comments:

  1. OOOOh My Gawd! this stuff amaaaaazes me! lol i do not understand much of it but i always find myself here lost for "hours" �� in the depths of all sorts of pages (("behind the scenes" if you will)) ahaha! �� i "LOVE THIS STUFF"! an really wish i could learn it more thoroughly! =) for now. . . ? i'll just play around to learn and try not to screw anything UP!
    { ●_●`} lmao! 10?! (1:00a)

    ReplyDelete
    Replies
    1. That's great! ^^ Thanks for the comment, I appreciate that. If you want to learn more of code, I would suggest following https://developer.mozilla.org/en-US/docs/Web/JavaScript/ for a wiki on JavaScript--it's how I learned, so it should be O.K.!

      Delete