This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
encoder.html
292 lines (250 loc) · 10.1 KB
/
encoder.html
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<!DOCTYPE html>
<html lang="en">
<head>
<title>TuringFonts - Encoder and scripts</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="icon" type="image/png" href="img/logo.ico"/>
<link rel="stylesheet" href="lib/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="lib/bootstrap/css/bootstrap-darkly.min.css" />
<script type="text/javascript" src="lib/jquery/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="lib/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="lib/angular/angular-1.3.15.min.js"></script>
<link rel="stylesheet" href="lib/highlights/styles/tomorrow-night.css" />
<script type="text/javascript" src="lib/highlights/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<link href='http://fonts.googleapis.com/css?family=Source+Code+Pro' rel='stylesheet' type='text/css'>
<style type="text/css">
@font-face {
font-family: 'arial_atbash';
src: url('fonts/arial/arial_atbash-webfont.eot');
src: url('fonts/arial/arial_atbash-webfont.eot?#iefix') format('embedded-opentype'),
url('fonts/arial/arial_atbash-webfont.woff2') format('woff2'),
url('fonts/arial/arial_atbash-webfont.woff') format('woff'),
url('fonts/arial/arial_atbash-webfont.ttf') format('truetype'),
url('fonts/arial/arial_atbash-webfont.svg#arialregular') format('svg');
font-weight: normal;
font-style: normal;
}
h1, h2, h3, h2 a, h2 a:hover {
font-family: 'Source Code Pro';
color: #88f;
}
h1 {
margin-top: 0;
}
div.content {
padding: 5px;
}
p, li {
font-size: 16px;
font-family: Verdana;
}
h2 a, h2 a:hover {
text-decoration: none;
}
input, textarea, select {
color: white;
background-color: #333;
border: 1px solid darkgray;
}
span.alpha {
color: #ffa;
}
div.output {
border: 1px solid darkgray;
padding: 3px;
color: #aff;
}
pre {
padding: 0;
}
</style>
<script type="text/javascript">
function encrypt(plain, cipher, text) {
plain = plain + plain.toUpperCase()
cipher = cipher + cipher.toUpperCase()
var newText = '';
for(var i=0; i<text.length; i++) {
var c = text.charAt(i);
var index = plain.indexOf(c)
if(index >= 0 && index < cipher.length) {
newText += cipher.charAt(index);
} else {
newText += c;
}
}
return newText;
}
var app = angular.module('myApp', []);
app.controller('encoderCtrl', function($scope) {
$scope.plainAlpha = "abcdefghijklmnopqrstuvwxyz";
$scope.cipherAlpha = "zyxwvutsrqponmlkjihgfedcba";
$scope.plainText = "Some sensitive text that only humans must be able to read";
$scope.update = function() { $scope.cipherText = encrypt($scope.plainAlpha, $scope.cipherAlpha, $scope.plainText); };
$scope.method = 'ROT13';
$scope.options = ['Atbash', 'ROT13', 'Zebra', 'Custom'];
$scope.methodChanged = function() {
$scope.plainAlpha = "abcdefghijklmnopqrstuvwxyz";
if($scope.method === 'Atbash') {
$scope.cipherAlpha = "zyxwvutsrqponmlkjihgfedcba";
}
if($scope.method === 'ROT13') {
$scope.cipherAlpha = "nopqrstuvwxyzabcdefghijklm";
}
if($scope.method === 'Zebra') {
$scope.cipherAlpha = "zebrascdfghijklmnopqtuvwxy";
}
$scope.update();
};
$scope.methodChanged();
});
</script>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="index.html"><img alt="" title="TuringFonts" src="img/logo-24.png"></a>
<a class="navbar-brand" href="index.html">TuringFonts</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-left">
<li><a href="index.html">Getting started</a></li>
<li><a href="advanced.html">Advanced topics</a></li>
<li><a href="encoder.html">Encoder</a></li>
</ul>
</div>
</div>
</nav>
<div class="content col-md-8 col-md-offset-2">
<h1>Encoder</h1>
<p>Select the substitution method that you want to use and enter the text that you want to encode.</p>
<p>At the <a href="index.html#downloads">downloads</a> section you will find some fonts that can be used when the substitution method used is either ROT13, Atbash or Zebra.
If you define a custom substitution method, you will need to create your own font, as indicated in the <a href="advanced.html">advanced documentation</a>.
<div ng-app="myApp" ng-controller="encoderCtrl">
<p><strong><big>Input</big></strong></p>
<p>
Substitution method:
<select ng-model="method" ng-options="item for item in options" ng-change="methodChanged()"></select>
</p>
<small>
<div class="row" style="margin-bottom: 3px;">
<div class="col-xs-2 text-right">Plaintext alphabet:</div>
<div class="col-xs-10 text-left">
<span class="alpha" ng-if="method !== 'Custom'">{{plainAlpha}}</span>
<input ng-if="method === 'Custom'" type="text" ng-model="plainAlpha" ng-change="update()" size="40" />
</div>
</div>
</small>
<small>
<div class="row" style="margin-bottom: 3px;">
<div class="col-xs-2 text-right">Ciphertext alphabet:</div>
<div class="col-xs-10 text-left">
<span class="alpha" ng-if="method !== 'Custom'">{{cipherAlpha}}</span>
<input ng-if="method === 'Custom'" type="text" ng-model="cipherAlpha" ng-change="update()" size="40" />
</div>
</div>
</small>
<br/>
<div>
<textarea ng-model="plainText" ng-change="update()" style="width:100%;"></textarea>
</div>
<br/>
<p><strong><big>Output</big></strong></p>
<div class="output">{{cipherText}}</div>
</div>
<br/>
<h2>Dynamic encoding</h2>
<p>If you want to encode your text at your server, or you need to encode content generated dynamically, you only have to implement an encoding function.</p>
<p>It's easy! Here you have examples in some of the most popular languages:</p>
<br/>
<p><strong><big>PHP</big></strong></p>
<pre><code class="php">function encrypt($plain, $cipher, $text) {
$plain = $plain . strtoupper($plain);
$cipher = $cipher . strtoupper($cipher);
$newText = '';
for($i=0; $i<strlen($text); $i++) {
$c = $text[$i];
$index = strrpos($plain, $c);
if($index && $index < strlen($cipher)) {
$newText = $newText . $cipher[$index];
} else {
$newText = $newText . $c;
}
}
return $newText;
}</code></pre>
<p><a href="http://ideone.com/qtgkDz" target="_blank">See live demo</a></p>
<br/>
<p><strong><big>JavaScript</big></strong></p>
<pre><code class="javascript">function encrypt(plain, cipher, text) {
plain = plain + plain.toUpperCase();
cipher = cipher + cipher.toUpperCase();
var newText = '';
for(var i=0; i<text.length; i++) {
var c = text.charAt(i);
var index = plain.indexOf(c);
if(index >= 0 && index < cipher.length) {
newText += cipher.charAt(index);
} else {
newText += c;
}
}
return newText;
}</code></pre>
<p><a href="http://ideone.com/sgJxuQ" target="_blank">See live demo</a></p>
<br/>
<p><strong><big>Python</big></strong></p>
<pre><code class="python">def encrypt(plain, cipher, text):
plain += plain.upper()
cipher += cipher.upper()
newText = ''
for c in text:
index = plain.find(c)
if(index >= 0 and index < len(cipher)):
newText += cipher[index]
else:
newText += c
return newText;</code></pre>
<p><a href="http://ideone.com/1APK9U" target="_blank">See live demo</a></p>
<br/>
<p><strong><big>Java</big></strong></p>
<pre><code class="java">public static String encrypt(String plain, String cipher, String text) {
plain = plain + plain.toUpperCase();
cipher = cipher + cipher.toUpperCase();
String newText = "";
for(int i=0; i<text.length(); i++) {
char c = text.charAt(i);
int index = plain.indexOf(c);
if(index >= 0 && index < cipher.length()) {
newText += cipher.charAt(index);
} else {
newText += c;
}
}
return newText;
}</code></pre>
<p><a href="http://ideone.com/S11kXI" target="_blank">See live demo</a></p>
<br/>
<p><strong><big>C#</big></strong></p>
<pre><code class="csharp">public static String encrypt(String plain, String cipher, String text) {
plain = plain + plain.ToUpper();
cipher = cipher + cipher.ToUpper();
String newText = "";
for(int i=0; i<text.Length; i++) {
char c = text[i];
int index = plain.IndexOf(c);
if(index >= 0 && index < cipher.Length) {
newText += cipher[index];
} else {
newText += c;
}
}
return newText;
}</code></pre>
<p><a href="http://ideone.com/raYryq" target="_blank">See live demo</a></p>
</div>
<a href="https://github.com/jfmdev/TuringFonts" target="_blank"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/52760788cde945287fbb584134c4cbc2bc36f904/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f77686974655f6666666666662e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png"></a>
</body>
</html>