Skip to content

Instantly share code, notes, and snippets.

@techbelly
Created May 17, 2015 00:40
Show Gist options
  • Save techbelly/7e76f92d01f9b2aef95c to your computer and use it in GitHub Desktop.
Save techbelly/7e76f92d01f9b2aef95c to your computer and use it in GitHub Desktop.
CipherSaber 2 in ruby
#!/usr/bin/env ruby
class CS;def d(t,k,n);r=[];s=(0..255).to_a;j=0;k.each_byte{|b|r<<b};n.times{0.upto(255){|i|j=(j+s[i]+r[i%r.length])%256;
s[i],s[j]=s[j],s[i]}};i,j=0,0;c="";t.each_byte{|b|i=(i+1)%256;j=(j+s[i])%256;s[i],s[j]=s[j],s[i];k=s[(s[i]+s[j])%256];c<<(k^b)};c;end;end
class CipherSaber < CS
def initialize(key,num)
@key = key
@num = num
end
def decrypt(text)
d(text,@key.clone,@num)
end
alias :encrypt :decrypt
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment