FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript/Ciphers/XORCipher.js at master · MMABSOUT/JavaScript · GitHub
MMABSOUT
/
JavaScript
Public
forked from
TheAlgorithms/JavaScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript
/
Ciphers
/
XORCipher.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
22 lines (20 loc) · 649 Bytes
Breadcrumbs
JavaScript
/
Ciphers
/
XORCipher.js
Copy path
File metadata and controls
22 lines (20 loc) · 649 Bytes
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
/**
*
@function
XORCipher
*
@description
- Encrypt using an XOR cipher
* The XOR cipher is a type of additive cipher.
* Each character is bitwise XORed with the key.
* We loop through the input string, XORing each
* character with the key.
*
@param
{
string
} str - string to be encrypted
*
@param
{
number
} key - key for encryption
*
@return
{
string
} encrypted string
*/
const
XORCipher
=
(
str
,
key
)
=>
{
if
(
typeof
str
!==
'string'
||
!
Number
.
isInteger
(
key
)
)
{
throw
new
TypeError
(
'Arguments type are invalid'
)
}
return
str
.
replace
(
/
.
/
g
,
(
char
)
=>
String
.
fromCharCode
(
char
.
charCodeAt
(
)
^
key
)
)
}
export
default
XORCipher
Back
|
FazBrowse Home
|
New Git URL