Skip to content

Instantly share code, notes, and snippets.

@ymmt2005
Created April 24, 2012 16:36
Show Gist options
  • Save ymmt2005/2481279 to your computer and use it in GitHub Desktop.
Save ymmt2005/2481279 to your computer and use it in GitHub Desktop.
pass phrase generator for Japanese
# -*- coding: utf-8 -*-
'''
パスフレーズがいいらしい
→ 日本人なんだから日本語フレーズがいいに決まっている
いい辞書ないかな
→ pubdic+
http://www.remus.dti.ne.jp/~endo-h/wnn/
平仮名→ローマ字
→ PyICU (ICU4C)
$ apt-get install python-pyicu
'''
from PyICU import Transliterator, UTransDirection
t = Transliterator.createInstance('Hiragana-Latin',
UTransDirection.UTRANS_FORWARD)
import codecs
import sys
if len(sys.argv) == 1:
print >>sys.stderr, "Usage: hoge.py PUBDIC.u"
sys.exit(1)
words = []
with codecs.open(sys.argv[1], encoding='EUC-JP') as f:
for line in f:
word = line.split()[0].replace(u'ー', u'-').replace(u'~', u'')
words.append( t.transliterate(word) )
from random import choice
phrase = []
for x in xrange(5):
phrase.append( choice( words ) )
print ' '.join(phrase)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment