To the Top

ROT47 Character Substitution Cipher

The ROT47 (Caesar cipher by 47 chars) is a simple character substitution cipher that replaces a character within the ASCII range [33, 126] with the character 47 character after it (rotation) in the ASCII table. It is an invertible algorithm i.e. applying the same algorithm to the input twice will get the origin text.
The page provides a Javascript implementation online ROT47 encoder/decoder.
Example: This page provides a Javascript online web-based ROT47 Encoder/Decoder.
will be translated to:
%9:D A286 [email protected]:56D 2 y2G2D4C:AE @?=:?6 H63\32D65 #~%cf [email protected]^[email protected]]

ROT47: same action can be used for encoding and decoding
ROT47 is a derivative of ROT13. ROT47 introduces mixed letters and symbols, therefore, the encoded text looks more obvious that text has been enciphered. The following is an online ROT47 cipher implemented by Javascript.

The ROT47 can be easily implemented by modern programming language in many many ways, e.g. using a lookup table. For example, the following PHP code uses strstr to convert the text by using a lookup table.

function str_rot47($str)
{
  return strtr($str, 
    '!"#$%&\'()*+,-./0123456789:;<=>[email protected][\]^_`abcdefghijklmnopqrstuvwxyz{|}~', 
    'PQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~!"#$%&\'()*+,-./0123456789:;<=>[email protected]'
  );
}

For more details, please refer to this post: The PHP str_rot47 implementation, and here is a PHP Rot47 Online Encoder/Decoder.

Alternatively, ROT47 can be implemented by computing directly the ROT47-ed ASCII of each given character.

function Rot47(const s: string): string;
var
  i, j: integer;
begin
  Result := s;
  for i := 1 to Length(s) do
  begin
    j := Ord(s[i]);
    if (j in [33..126]) then
    begin
      Result[i] := Chr(33 + ((j + 14) mod 94));
    end;
  end;
end;

API (Application Programmer Interface)

The API following has a rate-limit 1 call per second.
https://helloacm.com/api/rot47/?s=Hello ROT47
It will return JSON-encoded data:
"[email protected] #~%cf"
If $_GET parameter s is not specified, this API will use the $_POST variable s instead.
curl -X POST https://helloacm.com/api/rot47/ -d "s=ROT47 Rocks!"

ROT47 Implementation in PostgreSQL

Some offers the PostgreSQL plpgsql function that implements the ROT47 cipher:
CREATE OR REPLACE FUNCTION public.rot47(character varying)
RETURNS character varying AS
$BODY$
-- SAMPLE
/*
SELECT public.rot47($$Hello$$);
SELECT public.rot47([email protected]$$);
*/
DECLARE
s ALIAS FOR $1;
i INTEGER;
j INTEGER;
Result VARCHAR[];
BEGIN
FOR i IN 1..length(s) LOOP
j := ascii(substr(s,i,1));
IF (j >= 33 AND j <= 126) THEN
Result := array_append(Result, Chr(33 + mod(j + 14, 94))::varchar);
ELSE
Result := array_append(Result, substr(s,i,1)::varchar); 
END IF;
END LOOP;
RETURN array_to_string(Result, '');
END;$BODY$
LANGUAGE plpgsql VOLATILE
COST 1;
ALTER FUNCTION public.rot47(character varying)
OWNER TO postgres;

ROT47 Implemnetation in Node.Js (Javascript)

Someone is nice to wrap this up and provide it free in NPM (Node Package Manager) in NodeJS.
module.exports = function rot47(x)
{var s=[];for(var i=0;i<x.length;i++)
{var j=x.charCodeAt(i);if((j>=33)&&(j<=126))
{s[i]=String.fromCharCode(33+((j+ 14)%94));}
else
{s[i]=String.fromCharCode(j);}}
  return s.join('');}

See more details in Node Tool for ROT47

Example Usage:

gzip -d -c file.txt | base64 -D | rot47 > orig.txt

Pascal/Python/VBScript
Javascript Download

Use the ROT47 function in your application easily; rot47.pas - rot47.py - rot47.vbs (Is VBScript Dead?) - rot47.js - rot47c.js (Compressed)

Link here!

Just paste the HTML code, shown below, onto the site of your choice.
    <a href="https://rot47.net" title="Online ROT47 Encoder/Decoder">Online ROT47 Encoder</a>
Plain text example:
Online ROT47 Encoder

Share This


Page Edited: