-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
219 lines (176 loc) · 5.78 KB
/
Copy pathcode.js
File metadata and controls
219 lines (176 loc) · 5.78 KB
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
/*
Here are the different cyphers that we will include in our program:
all to lowercase
all to uppercase
uppercase the first word of each word
capitalize first letter of first word, add period on end "make a sentence"
more cypherish:
convert to binary
convert to morse code
randomize the words
randomize the letters generally
*/
//to lowercase
//use default string method:
//str.toLowerCase();
//to uppercase
//use default string method:
//str.toUpperCase();
//uppercase first letter of each word
function toUpperEachWord(str){
str = str.toLowerCase();
var strArray = str.split(" ");
var newString = "";
for(var i = 0; i < strArray.length; i++){
newString += strArray[i].substring(0, 1).toUpperCase() + strArray[i].substring(1);
if(i < strArray.length - 1){
newString += " ";
}
}
return newString
}
//make the string into a proper sentence
function toProperSentance(str){
if(str.length == 0) return str;
if(str.substr(-1) == "." || str.substr(-1) == "!" || str.substr(-1) == "?") return str.substring(0, 1).toUpperCase() + str.substring(1);
return str.substring(0, 1).toUpperCase() + str.substring(1) + ".";
}
//Convert string to binary
function toBinary(str){
var newString = "";
for(var i = 0; i < str.length; i++){
newString += str.charCodeAt(i).toString(2);
if(i < str.length - 1) newString += " ";
}
return newString;
}
//convert the string to morse code
function toMorseCode(str){
str = str.toLowerCase();
var morseAlphabet = {
'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': '--..', ' ': ' ',
'1': '.----', '2': '..---', '3': '...--', '4': '....-',
'5': '.....', '6': '-....', '7': '--...', '8': '---..',
'9': '----.', '0': '-----',
}
var newString = "";
//alert(morseAlphabet['a']);
for(var i = 0; i < str.length; i++){
if(morseAlphabet[str.charAt(i)] == undefined){
newString += str.charAt(i);
}else{
newString += morseAlphabet[str.charAt(i)];
}
}
return newString;
}
//randomize the letters in the string
function toRandLettering(str){
var firstLetter = 0;
var secondLetter = 0;
var newString = str;
for(var i = 0; i < str.length * 3; i++){
firstLetter = Math.floor(Math.random() * str.length);
secondLetter = Math.floor(Math.random() * str.length);
//now swop those letters
var temp = newString.charAt(firstLetter);
newString = newString.substring(0, firstLetter) +
newString.substring(secondLetter, secondLetter + 1) + newString.substring(firstLetter + 1);
newString = newString.substring(0, secondLetter) + temp + newString.substring(secondLetter + 1);
}
return newString;
}
//randomize the words around in the string
function toRandWording(str){
var wordsArray = str.split(" ");
var firstWord = 0;
var secondWord = 0;
for(var i = 0; i < wordsArray.length * 3; i++){
firstWord = Math.floor(Math.random() * wordsArray.length);
secondWord = Math.floor(Math.random() * wordsArray.length);
var temp = wordsArray[firstWord];
wordsArray[firstWord] = wordsArray[secondWord];
wordsArray[secondWord] = temp;
}
var newString = "";
for(var i = 0; i < wordsArray.length; i++){
newString += wordsArray[i];
if(i < wordsArray.length - 1) newString += " ";
}
return newString;
}
//caeser cipher, hold the dressing
function toCaesar(str, rotation){
while(rotation >= 26) rotation -= 26;
var newString = "";
for(var i = 0; i < str.length; i++){
var code = str.charCodeAt(i);
if(code >= 65 && code <= 90){
code += rotation;
if(code > 90) code -= 26;
}else if(code >= 97 && code <= 122){
code += rotation;
if(code > 122) code -= 26;
}else{
//number or something
}
newString += String.fromCharCode(code);
}
return newString;
}
//reverse the string
function toReverse(str){
var newString = "";
for(var i = str.length - 1; i >= 0; i--){
newString += str.charAt(i);
}
return newString;
}
//Atbash A = Z, B = Y, ...
function toAtBash(str){
var newString = "";
for(var i = 0; i < str.length; i++){
var code = str.charCodeAt(i);
if(code >= 65 && code <= 90){
code -= 65;
code = 25 - code;
code += 65;
}else if(code >= 97 && code <= 122){
code -= 97;
code = 25 - code;
code += 97;
}else{
//it's a number or a symbol
}
newString += String.fromCharCode(code);
}
return newString;
}
//ROT13 A = N, B = O, ...
function toRot13(str){
var newString = "";
for(var i = 0; i < str.length; i++){
var code = str.charCodeAt(i);
if(code >= 65 && code <= 90){
code -= 65;
code += 13;
if(code > 25) code -= 26;
code += 65;
}else if(code >= 97 && code <= 122){
code -= 97;
code += 13;
if(code > 25) code -= 26;
code += 97;
}else{
//it's a number or a symbol
}
newString += String.fromCharCode(code);
}
return newString;
}