Created
October 16, 2010 11:04
-
-
Save anonymous/629676 to your computer and use it in GitHub Desktop.
どう使うのか解りません
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mv(key,nn) | |
print "in mv\n" | |
init_curve(nn) | |
mktable(@CRV_G_x,@CRV_G_y) | |
ellip(key) | |
print "Pubkey_x=",@Pub_key_x,"\n" | |
print "Pubkey_y=",@Pub_key_y,"\n" | |
#command = { 'e' => 0, 'd' => 1}[(ARGV[0]||'').strip.downcase] | |
#data = ARGV[1] && IO.read(ARGV[1]) | |
#print "argv1=",ARGF.filename,"\n" | |
require 'securerandom' | |
f = File.open(ARGF.filename,"rb") | |
g = File.open(ARGF.filename + ".ecc","wb") | |
#=begin | |
int=0 | |
salt=SecureRandom.random_number(2**(32*8)) | |
# salt=[OpenSSL::Random.random_bytes(32)].pack("m") | |
# salt.each_byte{|c| int=(int<<8)^c} | |
# salt=int | |
print "salt=",salt,"\n" | |
mktable(@Pub_key_x,@Pub_key_y) | |
ellip(salt) | |
print "salt*Pubkey_x=",@Pub_key_x,"\n" | |
print "salt*Pubkey_y=",@Pub_key_y,"\n" | |
@Gen_key_x=@Pub_key_x | |
@Gen_key_y=@Pub_key_y | |
for i in 0..10000 | |
@I[i]=0 | |
end | |
ii=0 | |
mktable(@CRV_G_x,@CRV_G_y) | |
ellip(salt) | |
#=end | |
while((str=f.read(32))!=nil) | |
@I[ii]=str.size | |
ii=ii+1 | |
c=0 | |
i=0 | |
salt=0 | |
str.each_byte{|c| salt=(salt<<8)^c} | |
#print "length=",str.split(//s).length,"\n" | |
eadd(@Gen_key_x,@CRV_G_x,@Gen_key_y,@CRV_G_y,@CRV_p) | |
salt^=(@T_y%(2**8*str.size)) | |
@Gen_key_x=@T_x | |
@Gen_key_y=@T_y | |
=begin | |
# 巨大な数 salt をバイトごとの配列に変換(packが使えないので原始的に) | |
bytes = [] | |
while salt > 0 | |
salt, byte = salt >> 8, salt & 0xff | |
bytes.unshift(byte) # 望むエンディアネスによっては push かも。 | |
end | |
# バイトの配列をバイト文字列として書き出す | |
open(ARGF.filename + ".ecc", 'wb') {|out| out.print(bytes.pack('C*')) } | |
=end | |
g.write(salt) | |
g.write("\n") | |
end | |
f.close | |
g.close | |
end | |
def dec(key,nn) | |
print "in mv\n" | |
init_curve(nn) | |
mktable(@Pub_key_x,@Pub_key_y) | |
ellip(key) | |
print "dcPubkey_x=",@Pub_key_x,"\n" | |
print "dcPubkey_y=",@Pub_key_y,"\n" | |
salt=[32] | |
#OpenSSL::Random.random_bytes(32) | |
#print "salt=",salt,"\n" | |
command = { 'e' => 0, 'd' => 1}[(ARGV[0]||'').strip.downcase] | |
data = ARGV[1] && IO.read(ARGV[1]) | |
g = File.open(ARGF.filename + ".txt","wb") | |
f = File.open(ARGF.filename + ".ecc","rb") | |
lines = fields = 0 | |
ii=0 | |
open(ARGF.filename + ".ecc") {|file| | |
while l = file.gets | |
l=l.to_i | |
ls=@I[ii] | |
ii=ii+1 | |
=begin | |
value = 0 | |
# バイナリデータを読み込んでバイト列に分解 | |
raw = open(ARGF.filename + ".ecc"){|f| f.read.unpack('C*')} | |
# 数を復元 | |
until raw.empty? | |
value = (value << 8) + raw.shift | |
end | |
l=value | |
=end | |
#print "l=",ls,"\n" | |
eadd(@Pub_key_x,@CRV_G_x,@Pub_key_y,@CRV_G_y,@CRV_p) | |
@Pub_key_x=@T_x | |
@Pub_key_y=@T_y | |
lines += 1 | |
fields += l.to_s.split(',').size | |
l^=(@T_y%(2**8*ls)) | |
for i in 0..31 | |
salt[i]=0 | |
end | |
while(l>0) | |
i=0 | |
while(i<ls) | |
salt[i]=l&0xff | |
salt[i]=sprintf("%c",salt[i]) | |
l=(l>>8) | |
i=i+1 | |
end | |
end | |
i=ls-1 | |
while(i>-1) | |
g.write(salt[i]) | |
i=i-1 | |
end | |
end | |
} | |
puts "Total #{lines} lines, #{fields} fields" | |
#print "length=",str.split(//s).length,"\n" | |
f.close | |
g.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment