Platform
Resources
Pricing
Sign in
Get started
Hunter Brooks
Workspace
Fork
Published
By
Hunter Brooks
Edited
Nov 13, 2019
Insert cell
Insert cell
Insert cell
"TALK"
.
split
(
''
)
.
map
(
letter
=>
letter
.
charCodeAt
(
0
)
)
Insert cell
"TALK"
.
split
(
''
)
.
map
(
letter
=>
letter
.
charCodeAt
(
0
)
)
.
map
(
dec
=>
(
dec
>>>
0
)
.
toString
(
2
)
)
Insert cell
plaintext
=
"TALK"
.
split
(
''
)
.
map
(
letter
=>
letter
.
charCodeAt
(
0
)
)
.
map
(
dec
=>
(
dec
>>>
0
)
.
toString
(
2
)
)
.
reduce
(
(
total
,
part
)
=>
total
+
part
)
Insert cell
lfsr
=
(
init
,
length
)
=>
{
for
(
let
i
=
init
.
length
;
i
<
length
;
i
++
)
{
init
+=
mod2Add
(
init
.
charAt
(
i
-
3
)
,
init
.
charAt
(
i
-
1
)
)
;
}
return
init
;
}
Insert cell
key
=
lfsr
(
'101'
,
plaintext
.
length
)
;
Insert cell
cyphertext
=
{
let
answer
=
''
;
for
(
let
i
=
0
;
i
<
plaintext
.
length
;
i
++
)
{
answer
+=
mod2Add
(
plaintext
.
charAt
(
i
)
,
key
.
charAt
(
i
)
)
;
}
return
answer
;
}
Insert cell
function
mod2Add
(
a
,
b
,
...
rest
)
{
a
=
Number
(
a
)
;
b
=
Number
(
b
)
;
let
sum
=
Number
(
a
?
!
b
:
b
)
;
if
(
rest
.
length
)
{
return
mod2Add
(
sum
,
...
rest
)
;
}
return
sum
;
}
Insert cell
// mod2Add = (a,b) => {
// a = Number(a);
// b = Number(b);
// return Number(a ? !b : b);
// }
Insert cell
mod2Add
(
0
,
0
,
1
,
0
,
0
,
0
,
0
,
1
)
;
Insert cell
Insert cell
Insert cell
p3
=
(
{
plaintext
:
'100100100100100'
,
ciphertext
:
'01100010101110011101010001000110001010111001110101'
,
key
:
'111100001111000011110000111100001111000011110000111100001111000011110000'
,
}
)
Insert cell
stream_generator
=
{
let
answer
=
''
;
for
(
let
i
=
0
;
i
<
p3
.
plaintext
.
length
;
i
++
)
{
answer
+=
mod2Add
(
p3
.
plaintext
.
charAt
(
i
)
,
p3
.
ciphertext
.
charAt
(
i
)
)
;
}
return
answer
;
}
Insert cell
final_answer
=
{
let
answer
=
''
;
for
(
let
i
=
0
;
i
<
p3
.
ciphertext
.
length
;
i
++
)
{
answer
+=
mod2Add
(
p3
.
key
.
charAt
(
i
)
,
p3
.
ciphertext
.
charAt
(
i
)
)
;
}
return
answer
;
}
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
plaintext
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
lfsr
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
key
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cyphertext
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
mod2Add
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
p3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
stream_generator
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
final_answer
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML