FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaDataStructures/ECC/Encoder.java at master · benaich/JavaDataStructures · GitHub
benaich
/
JavaDataStructures
Public
Notifications
You must be signed in to change notification settings
Fork
7
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaDataStructures
/
ECC
/
Encoder.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
66 lines (59 loc) · 2.08 KB
Breadcrumbs
JavaDataStructures
/
ECC
/
Encoder.java
Copy path
File metadata and controls
66 lines (59 loc) · 2.08 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
57
58
59
60
61
62
63
64
65
66
package
ECC
;
import
static
ECC
.
Helpers
.
toBinary
;
import
java
.
math
.
BigInteger
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
List
;
public
class
Encoder
{
private
HashMap
<
Integer
,
Point
>
charTable
;
public
Encoder
(
HashMap
<
Integer
,
Point
>
charTable
) {
this
.
charTable
=
charTable
;
}
public
Matrix
encode
(
String
plainText
) {
Matrix
mMatrix
=
createMatrix
(
plainText
);
System
.
out
.
println
(
"
\n
2) Convert the list of points to a binary Matrix"
);
System
.
out
.
println
(
mMatrix
);
System
.
out
.
println
(
"
\n
3) Matrix Scrambling"
);
int
w
=
new
BigInteger
(
ECC
.
PAD
,
ECC
.
getRandom
()).
intValue
();
int
[]
bits
=
Helpers
.
toBinary
(
ECC
.
getRandom
().
nextInt
(
1024
),
ECC
.
PAD
*
2
);
System
.
out
.
println
(
"number of transformations, w = "
+
w
);
System
.
out
.
println
(
"Random sequence of bits, Bits = "
);
Helpers
.
print
(
bits
);
int
bit
,
i
=
0
;
do
{
bit
=
bits
[
i
];
if
(
bit
==
0
) {
mMatrix
.
scramble
(
true
);
}
else
{
mMatrix
.
scramble
(
false
);
}
if
(
i
==
bits
.
length
-
1
) {
i
=
0
;
}
else
{
i
++;
}
//System.out.println("scrambling...");
System
.
out
.
println
(
mMatrix
);
w
--;
}
while
(
w
>
0
);
return
mMatrix
;
}
private
Matrix
createMatrix
(
String
plainText
) {
List
<
Point
>
pList
=
new
ArrayList
<>();
for
(
Character
c
:
plainText
.
toCharArray
()) {
Point
p
=
charTable
.
get
((
int
)
c
.
charValue
());
pList
.
add
(
p
);
}
System
.
out
.
println
(
"
\n
1) Convert m to a list of Points"
);
pList
.
stream
().
forEach
(
System
.
out
::
print
);
System
.
out
.
println
(
""
);
List
<
Integer
>
bList
=
new
ArrayList
<>();
for
(
Point
p
:
pList
) {
String
str
=
toBinary
(
p
.
getX
()) +
""
+
toBinary
(
p
.
getY
());
for
(
int
i
=
0
;
i
<
str
.
length
();
i
++) {
bList
.
add
((
str
.
charAt
(
i
) ==
'0'
) ?
0
:
1
);
}
}
return
Helpers
.
listToMatrix
(
bList
);
}
}
Back
|
FazBrowse Home
|
New Git URL