Skip to content

Instantly share code, notes, and snippets.

@thomasjslone
Last active November 25, 2024 01:51
Show Gist options
  • Save thomasjslone/4988b1506ca8839df4067f4b7f910af3 to your computer and use it in GitHub Desktop.
Save thomasjslone/4988b1506ca8839df4067f4b7f910af3 to your computer and use it in GitHub Desktop.
keep text files hidden from your family (not encryption! only secure against non programmer people)
## locker builder ver 1.0, thomasjslone 2024-11-24
## Instructions:
##
## Locker is intended for use on windows, with ruby properly installed allowing you to double click the script to run it.
## Locker is NOT encryption and will not stop experienced programmers from decoding your information.
## Locker is intended to obfascate your files from people who have access to your computer.
##
## To begin, run this file('build.rb')
## You will be asked to select a directory and enter a file name.
## The ruby script generated can be stored with or away from the target file you want to protect, the locker can also have a set password.
##
## When you run the locker it will turn the target file into an unreadable mess of numbers, this will prevent your average person from reading them
## until you unlock them by running the same locker file again.
##
## One last time, THIS IS NOT ENCRYPTION and is not safe from any one with intermediate programming skills.
##
## Encoding scheme: Files must be utf8 ascii characters, those characters are translated into their ordinal values(0-255) and the result is a massive number which is then multiplied by 3
## to remove recognizable patterns. The source code of the locker file its self is also encoded and only decoded at the end of the file, **and also contains obfascation**comming to v1.1.
## These measures will stop basic scripters and computer literate people with no actual programming skills.
@chars = [] ; c = 0 ; 256.times{ @chars << c.chr.to_s ; c += 1 }
def exit_msg(str) ; puts str.to_s ; sleep 5.0 ; exit ; end
puts "Would you like to build a locker? (Y/N)"
if gets.chomp[0].downcase != "y" ; exit ; end
puts "Enter the directory the file will be located or just press enter if the locker will be in the same directory as the file."
print "Directory: "
inp = gets.chomp
if inp.to_s == "" ; @dir = nil
elsif File.directory?(inp) ; @dir = inp
else ; exit_msg("No such directory: " + inp.to_s)
end
puts "Enter the name of the file including extension."
print "File: "
inp = gets.chomp
if inp.to_s == "" ; exit_msg("File name cannot be blank.")
else
@name = inp.to_s
end
puts "Would you like to set a password for the locker? (Y/N)"
if gets.chomp[0].downcase == "y"
@require_password = true
loop do
print "Password: "
@password = gets.chomp
puts "Use this password? (Y/N)"
if gets.chomp[0].downcase == "y" ; break ; end
end
p = []
@password.split('').each{ |ch|
n = @chars.index(ch).to_s
loop do ; if n.to_s.length < 3; n="0"+n ; else; break ; end ; end
p << n
}
@password = p.join('')
else
@require_password = false
end
##build script
@data = []
if @dir == nil
@data << "@dir = Dir.getwd"
else
@data << "@dir = " + @dir.to_s
end
@script = []
@data << '@name = __FILE__.split("/")[-1].split(".rb")[0].to_s'
@data << '@path = @dir + "/" + @name'
#@data << '@chars = [] ; c = 0 ; 256.times{ @chars << c.chr.to_s ; c += 1 }'
@data << '@data = "" ; @ndata = ""'
@data << 'def exit_msg(str) ; puts str.to_s ; sleep 5.0 ; exit ; end'
if @require_password == true
@data << 'print "Password: " ; @string = "" ; gets.chomp.split("").each do |c| ; c = c.ord.to_s ; loop do ; if c.length == 3 ; break ; end ; c = "0"+c ; end ; @string << c ; end'
@data << 'if @string.to_s != "' + @password.to_s + '"' + ' ; exit ; end'
end
@data << 'if File.file?(@path) == false ; exit_msg("File doesnt exist: "+@name) ; end'
@data << 'begin ; f = File.open(@path,"r") ; @data = f.read ; f.close ; rescue ; exit_msg("Failed to read file.") ; end'
@data << 'if @data.length == 0 ; exit_msg("File is empty, please write file name with extension on the first line.") ; end'
@data << 'if @data.to_s.downcase[0..8] == @name.to_s ; begin ; str=@data; numbers=[] ; str.split("").each{ |ch| ; n = @chars.index(ch).to_s ; loop do ; if n.to_s.length < 3; n="0"+n ; else; break ; end ; end ; numbers << n ; } ; @ndata = numbers.join("") ; @ndata = "1" + @ndata ; @ndata = @ndata.to_i ; @ndata = @ndata * 3 ; @ndata = @ndata.to_i ; rescue ; exit_msg("Failed to encode file data.") ; end ; begin ; f = File.open(@path,"w") ; f.write(@ndata) ; f.close ; puts "EN-CODED" ; sleep 0.5 ; exit ; rescue ; exit_msg("Failed to write encoded data to file.") ; end ; end'
@data << 'begin ; @data = @data.to_i ; @data = @data / 3 ; @data = @data.to_s[1..-1] ; chars=[] ; [email protected]("") ; loop do ; if str.length == 0; break; end ; chars<<@chars[str[0..2].join("").to_i] ; 3.times{ str.delete_at(0) } ; end ; @ndata = chars.join("") ; rescue ; exit_msg("Failed to decode file data.") ; end ; begin ; f = File.open(@path,"w") ; f.write(@ndata) ; f.close ; puts "DE-CODED" ; sleep 0.5 ; exit ; rescue ; exit_msg("Failed to write encoded data to file.") ; end'
@data = @data.join(";")
numbers=[]
@data.split('').each{ |ch|
n = @chars.index(ch).to_s
loop do
if n.to_s.length < 3; n="0"+n
else; break
end
end
numbers << n
}
@data = numbers.join('')
@script << '@payload="'+@data+'"'
@script << '@chars = [] ; c = 0 ; (0..255).each { |c| ; @chars << c.chr.to_s }'
@script << 'chars=[];[email protected]("") ; loop do ; if str.length == 0; break; end ; chars<<@chars[str[0..2].join("").to_i] ; 3.times{ str.delete_at(0) }; end; instance_eval(chars.join(""))'
@script = @script.join(";")
f = File.open(Dir.getwd + "/" + @name.to_s + ".rb", "w")
f.write(@script)
f.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment