Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Code from this video : https://www.youtube.com/watch?v=RqbtV4cURI0
- module CR
- def self.encrypt(x,key)
- result = ""
- srand(((954938*key)%0xFFFFFF)+2)
- x.each_byte{|y|
- result << ((y+rand(444)+3)%256).chr
- }
- return result
- end
- def self.decrypt(x,key)
- result = ""
- srand(((954938*key)%0xFFFFFF)+2)
- x.each_byte{|y|
- result << ((y-rand(444)-3)%256).chr
- }
- return result
- end
- def self.encrypt_file(x,y,k)
- file = File.open(x,'rb')
- data = file.read
- file.close
- file = File.open(y,'wb')
- file.write(CR.encrypt(data,k))
- file.close
- end
- def self.decrypt_file(x,y,k)
- file = File.open(x,'rb')
- data = file.read
- file.close
- file = File.open(y,'wb')
- file.write(CR.decrypt(data,k))
- file.close
- end
- end
- begin
- print "Podaj metode :\n0-szyfruj\n1-deszyfruj\n"
- mode = gets.chomp!.to_i
- print "Podaj plik do szyfrowania :\n"
- filename = gets.chomp.to_s
- print "Podaj plik docelowy :\n"
- dest = gets.chomp.to_s
- print "Podaj klucz :\n"
- key = gets.chomp.to_i
- case mode
- when 0 then CR.encrypt_file(filename,dest,key);print "\nSzyfrowanie pomyslne.";$stdin.gets
- when 1 then CR.decrypt_file(filename,dest,key);print "\nDeszyfrowanie pomyslne.";$stdin.gets
- else
- print "Zly tryb"
- end
- rescue => e
- print "Wystapil blad : #{e}\n"
- print "Nacisnij ENTER by wyjsc\n"
- $stdin.gets
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement