blob: a974ea1fb749b95f0198e1879477d67efc0e6bbf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
require 'ayk/jcryption'
#
describe JCryption do
#
describe 'Bignum' do
it '#to_bytes #from_bytes should work' do
0x217962755220666f207463657073612074656577732061207369206d756e676942.should eql Bignum.from_bytes(0x217962755220666f207463657073612074656577732061207369206d756e676942.to_bytes)
end
it '#bits' do
K_BITS = 1024
k = JCryption.gen_keypair( K_BITS )
k.n.to_i.bits.should eql k.d.to_i.bits
k.d.to_i.bits.should eql k.d.to_i.bits
k.d.to_i.bits.should eql K_BITS
k.p.to_i.bits.should eql k.q.to_i.bits
k.q.to_i.bits.should eql k.q.to_i.bits
k.q.to_i.bits.should eql K_BITS/2
end
end
#
describe 'JCryption' do
it 'should decrypt data' do
data = '50c412c556a9fab55b50bd0d989067b341f9cdbf12ccb65aeb69dbb360a8e0dbd2069d686873b659b1be7a4c78fe631d362dbf538a5298ecaff19f78cd859897a7317c71b51b90e0a8c03e10059b68826bfeb194a4339a0ecc4a571ba9066fcf3504ffe76e07468cbe03337d3cfebd4efe687f5da72bf694dada987cea884180 ac07cc8462ce0f3e23dafe5d19f47eb33024c91de48413a971bf3b88c159090a26933f694d868bad61517a817f57998ed57bcebcd46a4ed8661cec3e24a8cdf21595902c2fd566820382e2d4f2ee7f1f11fa87a760bcecdf46282147d2c3a1afed3797d22296abcc3b1289489e7c265b3b4223bf93cbf0bb5122c021501a4305'
d = 142955580847936812437193870755035814405124627347905842843339476660410062601811480700441889718210202009243007436072050916187661826876350920486486397010450730779696290631486871265879746303575786048408069636369193884693458677811152828648243101513361320608836252500169104146911809960770571514285315905292345077217
n = 144356479900636891214255168759692179915080702955265792860263158994365175771327391113617049451662409039610467917872667615201472907166228721836687554904761268852157980063791071632316452235833332213934315100709197309374114347503598139080114451506623646859901230057693420846126487025125157251928362812236904436763
h = JCryption::decrypt( data, d, n).split('&').inject({}) { |h_,vk| v,k = vk.split '='; h_[v]=k; h_ }
h['username'].should eql "my_username"
h['passwd'].should eql "my_password"
h['timestamp'].should eql "1252937955"
end
end
end
#
|