FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
randomJavaScript/rotX.js at master · ram46/randomJavaScript · GitHub
ram46
/
randomJavaScript
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
randomJavaScript
/
rotX.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (49 loc) · 1.75 KB
Breadcrumbs
randomJavaScript
/
rotX.js
Copy path
File metadata and controls
56 lines (49 loc) · 1.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
Rot1, Rot2, Rot3 ... Rot25 encoding implementation
The encodeToRotX() function takes two arguments - string and number of places to rotate.
Example,
encodeToRotX('// Does this test work ? yep looks like it!', 13);
*/
function
encodeToRotX
(
inputStr
,
rotNum
)
{
var
inputList
=
inputStr
.
split
(
''
)
;
var
alphabet
=
'abcdefghijklmnopqrstuvwxyz'
;
var
outputList
=
[
]
;
for
(
var
i
=
0
;
i
<
inputList
.
length
;
i
++
)
{
var
inputChar
=
inputList
[
i
]
;
if
(
IsCharNotAlphabet
(
inputChar
,
alphabet
)
)
{
outputList
=
processNonAlphabets
(
outputList
,
inputChar
)
;
continue
;
}
else
{
if
(
IsCharLowerCase
(
alphabet
,
inputChar
)
)
{
outputList
=
processAlphabets
(
outputList
,
alphabet
,
inputChar
,
rotNum
)
;
}
else
{
outputList
=
processAlphabets
(
outputList
,
alphabet
.
toUpperCase
(
)
,
inputChar
,
rotNum
)
;
}
}
}
return
outputList
.
join
(
''
)
;
}
function
IsCharNotAlphabet
(
inputChar
,
alphabet
)
{
return
(
(
alphabet
.
indexOf
(
inputChar
)
===
-
1
)
&&
(
alphabet
.
toUpperCase
(
)
.
indexOf
(
inputChar
)
===
-
1
)
)
;
}
function
IsCharLowerCase
(
alphabet
,
inputChar
)
{
return
alphabet
.
indexOf
(
inputChar
)
!==
-
1
;
}
function
processNonAlphabets
(
outputList
,
inputChar
)
{
outputList
=
outputList
.
concat
(
inputChar
)
;
return
outputList
;
}
function
processAlphabets
(
outputList
,
alphabet
,
inputChar
,
rotNum
)
{
var
alphabetList
=
alphabet
.
split
(
''
)
;
var
origIndex
=
alphabet
.
indexOf
(
inputChar
)
;
var
newIndex
=
origIndex
+
rotNum
;
if
(
newIndex
>
25
)
{
var
startFromBeginningIndex
=
newIndex
-
26
;
outputList
=
outputList
.
concat
(
alphabetList
[
startFromBeginningIndex
]
)
;
}
else
{
outputList
=
outputList
.
concat
(
alphabetList
[
newIndex
]
)
;
}
return
outputList
;
}
var
output
=
encodeToRotX
(
'// Does this test work ? yep looks like it!'
,
13
)
;
console
.
log
(
output
)
;
Back
|
FazBrowse Home
|
New Git URL