All pastes #629601 Raw Edit

Mine

public ruby v1 · immutable
·published 2007-07-22 13:41 UTC
rendered paste body
class DocDB	def initialize(dbname,path = '.',overwrite = 1)		@dbname = dbname		@path   = "#{path}/#{@dbname}"		if File.exist?(@path)			@db = File.open(@path,'r')		else			@db = File.new(@path,'w+')		end		if overwrite < 1 then require 'ftools'; File.move(@path,"#{@path}~") end	end	def encrypt(key,blocksize)		f = File.new(@path,'w+')		@key = key		@keyarr = []		ciphertext = 0b0111000101101101011001010011101000100000011001101		encarr = []		encstr = ''		crypt = []		file = String.new		@db.each_line do |line|			file = "#{file}#{line}"		end		i = 0		@key.each_char{ |chr|			@keyarr.push(chr[0])				}		file.each_block(blocksize) { |block|			reversestr = ''			crypt[i] = block			buffer = Array.new			crypt[i].each_char { |chr|				buffer.push(chr[0].to_s(2).pad(-1))			}			ciphertext = (@keyarr.to_s.to_i - (buffer.to_s.to_i(2) ^ ciphertext))			ciphertext.to_s(2).each_char {				reversestr= reversestr.push('1')			}			ciphertext = ciphertext ^ reversestr.to_i(2)			encarr.push(ciphertext)			i+=1		}		j = 0		encarr.each do |str|			i = 0			while i < str.to_s(2).length				f.write(str.to_s(2).pad(-1)[i,8].to_i(2).to_s(26).pad(-1,2))				i+=8				j+=1			end		end		f.close	endend