-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathceaser.js
463 lines (406 loc) · 8.58 KB
/
ceaser.js
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
/**
* --------------------------------------------------------
* goal: to a function in ceaser n+shift => encrypted text\
*
* author cryptograghi
*
*/
// declares not to be changed
// letters is our string of letters
// map is a dictionaty map
// map shift is a new dictionary with the shift applied
// shift is the shift we want to use on our letters
// these are the settting for the program
// inmutable varibles
const LETTERS = GetTable(false);
const MAP = MapKeys(LETTERS);
const SHIFT = 13;
const MAPSHIFT = MapShift(MAP, SHIFT);
/**
* function: GetTable
* purpose: to get all ascii characters
* parms: one bool filter if true will only show character a-z A-z 0-9
* false with show symbols etc..`` *
*
*/
function GetTable(filter)
{
string = '';
if (filter === true)
{
for (var i = 32; i <= 126; i++)
{
// returns filtered list based on the char code
if(i >= 65 && i <= 90)
{
string += String.fromCharCode(i);
}
else if( i >= 97 && i <= 122)
{
string += String.fromCharCode(i);
} else {
}
}
// return strings from ascii codes
} else {
for(var i = 32; i <= 126; i++)
{
string += String.fromCharCode(i);
}
// return strings from ascii codes
}
return string;
}
// tests
//GetTable(true);
//GetTable(false);
/*
* function: map function
*
* purpose: to create a dictionary map that
* we will use later [a] = a
* output: [a] = a [b] = b etc....
*
*/
function MapKeys(input)
{
// create object that kill contain the keys
var map = { };
for (let i = 0; i < input.length; i++)
{
map[input[i]] = input[i];
}
return map;
}
// tests
//console.log(MapKeys(GetTable(true)));
/* output:
A: 'A',
B: 'B',
C: 'C',
D: 'D',
E: 'E',
F: 'F',
G: 'G',
H: 'H',
I: 'I',
J: 'J',
K: 'K',
L: 'L',
M: 'M',
N: 'N',
O: 'O',
P: 'P',
Q: 'Q',
R: 'R',
S: 'S',
T: 'T',
U: 'U',
V: 'V',
W: 'W',
X: 'X',
Y: 'Y',
Z: 'Z',
a: 'a',
b: 'b',
c: 'c',
d: 'd',
e: 'e',
f: 'f',
g: 'g',
h: 'h',
i: 'i',
j: 'j',
k: 'k',
l: 'l',
m: 'm',
n: 'n',
o: 'o',
p: 'p',
q: 'q',
r: 'r',
s: 's',
t: 't',
u: 'u',
v: 'v',
w: 'w',
x: 'x',
y: 'y',
z: 'z' */
/**
*
* FUNCTION MAPSHIFT
* PURPOSE: TO use a the letter object we created with MAP KEYS
* AND CREATE A NEW DICTIONARY WILL RECPECTED SHIFT A = C
* BUT WILL ONLY NEED THE ORGINAL
*/
function MapShift(currentMap, shift)
{
// lets create a new map of the new dictonarys now
for (keys in currentMap)
{
// check if the keys are actually valid
if (currentMap.hasOwnProperty(keys) == true)
{
let ASCII = keys.charCodeAt(keys);
// apply the shift
if (ASCII >= 65 && ASCII <= 90)
{
// apply shift
let SHIFTASCII = ASCII + shift;
// check number
if (SHIFTASCII > 90)
{
// dont change just minus the alphebet
SHIFTASCII = SHIFTASCII - 26;
currentMap[keys] = String.fromCharCode(SHIFTASCII);
} else {
// add shift to our map
currentMap[keys] = String.fromCharCode(SHIFTASCII);
}
}
else if (ASCII >= 97 && ASCII <= 122)
{
// apply shift for next squence of characters
let SHIFTASCII = ASCII + shift;
// trigger
if (SHIFTASCII > 122)
{
// above our thresehold
SHIFTASCII = SHIFTASCII - 26;
currentMap[keys] = String.fromCharCode(SHIFTASCII);
}
else
{
currentMap[keys] = String.fromCharCode(SHIFTASCII);
}
}
}
}
return currentMap;
}
// TESTS
//console.log(MapShift(MAP, SHIFT));
/*
output:
'0': '0',
'1': '1',
'2': '2',
'3': '3',
'4': '4',
'5': '5',
'6': '6',
'7': '7',
'8': '8',
'9': '9',
' ': ' ',
'!': '!',
'"': '"',
'#': '#',
'$': '$',
'%': '%',
'&': '&',
"'": "'",
'(': '(',
')': ')',
'*': '*',
'+': '+',
',': ',',
'-': '-',
'.': '.',
'/': '/',
':': ':',
';': ';',
'<': '<',
'=': '=',
'>': '>',
'?': '?',
'@': '@',
A: 'N',
B: 'O',
C: 'P',
D: 'Q',
E: 'R',
F: 'S',
G: 'T',
H: 'U',
I: 'V',
J: 'W',
K: 'X',
L: 'Y',
M: 'Z',
N: 'A',
O: 'B',
P: 'C',
Q: 'D',
R: 'E',
S: 'F',
T: 'G',
U: 'H',
V: 'I',
W: 'J',
X: 'K',
Y: 'L',
Z: 'M',
'[': '[',
'\\': '\\',
']': ']',
'^': '^',
_: '_',
'`': '`',
a: 'n',
b: 'o',
c: 'p',
d: 'q',
e: 'r',
f: 's',
g: 't',
h: 'u',
i: 'v',
j: 'w',
k: 'x',
l: 'y',
m: 'z',
n: 'a',
o: 'b',
p: 'c',
q: 'd',
r: 'e',
s: 'f',
t: 'g',
u: 'h',
v: 'i',
w: 'j',
x: 'k',
y: 'l',
z: 'm',
'{': '{',
'|': '|',
'}': '}',
'~': '~'
*/
/**
*
* function: to pack the input => the data to encrypt
*
* purpose: to pack the function to encrypt the message based on the shift level ie level of N
*/
function Pack(input, MAPSHIFT)
{
// ENCRYPT DATA AND PUSH ENCRYPTED STRING TO VAR SEED
SEED = ""
for (let i = 0; i <= input.length; i++)
{
for (letters in MAPSHIFT)
{
// check if our object name matches the letters
// push into seed if there is a match
if (letters === input[i])
{
SEED += MAPSHIFT[letters];
}
}
}
return SEED;
}
// TESTS
//console.log(Pack("TST", MAPSHIFT));
// output => GFG
/*
function: unPACK
purpose: to decrypt the data
input => is an encrypted string
MAPSHIFT => is the SHIFT APPLIED TO encrypted data
*/
function unPack(input, MAPSHIFT)
{
/// varible to push decrypted string into
UNPACKED_SEED = "";
for (let x = 0; x < input.length; x++)
{
// MAPSHIFT CONTAINER OUR DICTIONARY OF LETTERS
// DECLARE ARE AT TOP OF FILE
for (letters in MAPSHIFT)
{
// search though all the letters
if (MAPSHIFT[letters] == input[x])
{
UNPACKED_SEED += letters;
}
}
}
return UNPACKED_SEED;
}
//var test = Pack("STRINGS", MAPSHIFT);
//console.log(test);
//console.log(unPack(test, MAPSHIFT));
/*
output:
test => FGEVATF
test put into unpack function => STRINGS
*/
/**
* function: boomboom
* purpose: to crack the encryption using all possible matches
*
*/
function BoomBoom(data, shift_limit)
{
console.log("starting the cracking:......................");
var list = [];
for (let i = 0; i < shift_limit; i++)
{
// call the map
const BOOM = MapShift(MAP, i);
console.log("------------------------------------------");
console.log("Starting attempt:", i);
Guess = unPack(data, BOOM);
list.push(Guess);
console.log(Guess);
console.log("Finished attempted:", i)
console.log("-------------------------------------------");
}
console.log("Possible Matches: ")
for (let x = 0; x < list.length; x++)
{
if (list[x] != "")
{
console.log("try: ", x, list[x]);
}
}
return "FINISHED!";
}
// tests
test = Pack("my super secret string", MAPSHIFT);
BoomBoom(test, 26);
/*
output:
Possible Matches:
try: 0 zl fhcre frperg fgevat
try: 1 yk egbqd eqodqf efduzs
try: 2 xj dfapc dpncpe dectyr
try: 3 wi cezob combod cdbsxq
try: 4 vh bdyna bnlanc bcarwp
try: 5 ug acxmz amkzmb abzqvo
try: 6 tf zbwly zljyla zaypun
try: 7 se yavkx ykixkz yzxotm
try: 8 rd xzujw xjhwjy xywnsl
try: 9 qc wytiv wigvix wxvmrk
try: 10 pb vxshu vhfuhw vwulqj
try: 11 oa uwrgt ugetgv uvtkpi
try: 12 nz tvqfs tfdsfu tusjoh
try: 13 my super secret string bingo :)
try: 14 lx rtodq rdbqds rsqhmf
try: 15 kw qsncp qcapcr qrpgle
try: 16 jv prmbo pbzobq pqofkd
try: 17 iu oqlan oaynap opnejc
try: 18 ht npkzm nzxmzo nomdib
try: 19 gs mojyl mywlyn mnlcha
try: 20 fr lnixk lxvkxm lmkbgz
try: 21 eq kmhwj kwujwl kljafy
try: 22 dp jlgvi jvtivk jkizex
try: 23 co ikfuh iushuj ijhydw
try: 24 bn hjetg htrgti higxcv
try: 25 am gidsf gsqfsh ghfwbu
*/
// enjoy