3 # Electrum - lightweight Bitcoin client
4 # Copyright (C) 2011 thomasv@gitorious
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # list of words from http://en.wiktionary.org/wiki/Wiktionary:Frequency_lists/Contemporary_poetry
1656 # Note about US patent no 5892470: Here each word does not represent a given digit.
1657 # Instead, the digit represented by a word is variable, it depends on the previous word.
1659 def mn_encode( message ):
1661 for i in range(len(message)/8):
1662 word = message[8*i:8*i+8]
1666 w3 = ((x/n/n) + w2)%n
1667 out += [ words[w1], words[w2], words[w3] ]
1670 def mn_decode( wlist ):
1672 for i in range(len(wlist)/3):
1673 word1, word2, word3 = wlist[3*i:3*i+3]
1674 w1 = words.index(word1)
1675 w2 = (words.index(word2))%n
1676 w3 = (words.index(word3))%n
1677 x = w1 +n*((w2-w1)%n) +n*n*((w3-w2)%n)
1682 if __name__ == '__main__':
1684 if len( sys.argv ) == 1:
1685 print 'I need arguments: a hex string to encode, or a list of words to decode'
1686 elif len( sys.argv ) == 2:
1687 print ' '.join(mn_encode(sys.argv[1]))
1689 print mn_decode(sys.argv[1:])