Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
5714a827
Commit
5714a827
authored
Apr 09, 2014
by
Maran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small tweaks to mnemonic
parent
272b135b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
52 deletions
+54
-52
mnemonic.go
ethutil/mnemonic.go
+54
-52
No files found.
ethutil/mnemonic.go
View file @
5714a827
...
@@ -5,6 +5,60 @@ import (
...
@@ -5,6 +5,60 @@ import (
"strconv"
"strconv"
)
)
// TODO: See if we can refactor this into a shared util lib if we need it multiple times
func
IndexOf
(
slice
[]
string
,
value
string
)
int64
{
for
p
,
v
:=
range
slice
{
if
v
==
value
{
return
int64
(
p
)
}
}
return
-
1
}
func
MnemonicEncode
(
message
string
)
[]
string
{
var
out
[]
string
n
:=
int64
(
len
(
words
))
for
i
:=
0
;
i
<
len
(
message
);
i
+=
(
len
(
message
)
/
8
)
{
x
:=
message
[
i
:
i
+
8
]
bit
,
_
:=
strconv
.
ParseInt
(
x
,
16
,
64
)
w1
:=
(
bit
%
n
)
w2
:=
((
bit
/
n
)
+
w1
)
%
n
w3
:=
((
bit
/
n
/
n
)
+
w2
)
%
n
out
=
append
(
out
,
words
[
w1
],
words
[
w2
],
words
[
w3
])
}
return
out
}
func
MnemonicDecode
(
wordsar
[]
string
)
string
{
var
out
string
n
:=
int64
(
len
(
words
))
for
i
:=
0
;
i
<
len
(
wordsar
);
i
+=
3
{
word1
:=
wordsar
[
i
]
word2
:=
wordsar
[
i
+
1
]
word3
:=
wordsar
[
i
+
2
]
w1
:=
IndexOf
(
words
,
word1
)
w2
:=
IndexOf
(
words
,
word2
)
w3
:=
IndexOf
(
words
,
word3
)
y
:=
(
w2
-
w1
)
%
n
z
:=
(
w3
-
w2
)
%
n
// Golang handles modulo with negative numbers different then most languages
// The modulo can be negative, we don't want that.
if
z
<
0
{
z
+=
n
}
if
y
<
0
{
y
+=
n
}
x
:=
w1
+
n
*
(
y
)
+
n
*
n
*
(
z
)
out
+=
fmt
.
Sprintf
(
"%08x"
,
x
)
}
return
out
}
// Electrum word list
// Electrum word list
var
words
[]
string
=
[]
string
{
var
words
[]
string
=
[]
string
{
"like"
,
"like"
,
...
@@ -1634,55 +1688,3 @@ var words []string = []string{
...
@@ -1634,55 +1688,3 @@ var words []string = []string{
"weapon"
,
"weapon"
,
"weary"
,
"weary"
,
}
}
var
n
int64
=
1626
func
IndexOf
(
slice
[]
string
,
value
string
)
int64
{
for
p
,
v
:=
range
slice
{
if
v
==
value
{
return
int64
(
p
)
}
}
return
-
1
}
func
MnemonicEncode
(
message
string
)
[]
string
{
var
out
[]
string
for
i
:=
0
;
i
<
len
(
message
);
i
+=
(
len
(
message
)
/
8
)
{
x
:=
message
[
i
:
i
+
8
]
bit
,
_
:=
strconv
.
ParseInt
(
x
,
16
,
64
)
w1
:=
(
bit
%
n
)
w2
:=
((
bit
/
n
)
+
w1
)
%
n
w3
:=
((
bit
/
n
/
n
)
+
w2
)
%
n
out
=
append
(
out
,
words
[
w1
],
words
[
w2
],
words
[
w3
])
}
return
out
}
func
MnemonicDecode
(
wordsar
[]
string
)
string
{
var
out
string
for
i
:=
0
;
i
<
len
(
wordsar
);
i
+=
3
{
word1
:=
wordsar
[
i
]
word2
:=
wordsar
[
i
+
1
]
word3
:=
wordsar
[
i
+
2
]
w1
:=
IndexOf
(
words
,
word1
)
w2
:=
IndexOf
(
words
,
word2
)
w3
:=
IndexOf
(
words
,
word3
)
y
:=
(
w2
-
w1
)
%
n
z
:=
(
w3
-
w2
)
%
n
// Golang handles modulo with negative numbers different then most languages
// The modulo can be negative, we don't want that.
if
z
<
0
{
z
+=
n
}
if
y
<
0
{
y
+=
n
}
x
:=
w1
+
n
*
(
y
)
+
n
*
n
*
(
z
)
out
+=
fmt
.
Sprintf
(
"%08x"
,
x
)
}
return
out
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment