Skip to content

Instantly share code, notes, and snippets.

@gyuque
Created May 13, 2011 14:49
Show Gist options
  • Save gyuque/970661 to your computer and use it in GitHub Desktop.
Save gyuque/970661 to your computer and use it in GitHub Desktop.
般若心経SHA1
require 'digest/sha1'
HANNYA_CHARS = [
'観','菩','薩','行','深','般','若','波',
'羅','蜜','多','時','照','見','五','蘊',
'皆','空','度','苦','厄','舎','利','阿',
'不','異','即','是','想','心','経','如'
]
def hannya_sha1(src)
s = []
bits = Digest::SHA1.digest(src).unpack("b*").join('')
32.times{
bits.sub!(/^[01]{5}/, '')
s << HANNYA_CHARS[$&.to_i(2)]
}
s.join('')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment