Skip to content

Instantly share code, notes, and snippets.

@thomasjslone
Last active September 14, 2016 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasjslone/85801535421f97575ac22fa9271117da to your computer and use it in GitHub Desktop.
Save thomasjslone/85801535421f97575ac22fa9271117da to your computer and use it in GitHub Desktop.
RBX is now known as Renv
begin
require 'rbconfig'
rescue => exception
raise "Ruby Environment could not start because library is missing. \n" + execption.to_s + "\n" + exception.backtrace.join("\n").to_s
end
@host_os = RbConfig::CONFIG["host_os"].to_s
@prime_numbers = ['3575263','3575269','3575291','3575317','3575333','3575339','3575357','3575371','3575413','3575437','3575441','3575449','3575471','3575483','3575503','3575519','3575521','3575531','3575549','3575573','3575581','3575597','3575599','3575609','3575617','3575639','3575647','3575653','3575657','3575687','3575701','3575707','3575771','3575783','3575821','3575839','3575843','3575849','3575861','3575863','3575867','3575893','3575909','3575911','3575917','3575921','3575927','3575941','3575959','3575981','3575983','3575987','3575993','3576029','3576031','3576037','3576043','3576073','3576091','3576101','3576119','3576121','3576127','3576151','3576163','3576179','3576187','3576217','3576227','3576233','3576257','3576269','3576283','3576289','3576299','3576311','3576319','3576323','3576329','3576359','3576361','3576373','3576401','3576407','3576413','3576421','3576437','3576451','3576467','3576473','3576479','3576509','3576557','3576571','3576577','3576583','3576593','3576607','3576637','3576649','3576673','3576691','3576721','3576733','3576761','3576779','3576791','3576803','3576809','3576829','3576829','3576847','3576863','3576907','3576913','3576941','3576943','3576961','3576967','3576971','3576977','3577019','3577027','3577031','3577037','3577061','3577081','3577099','3577109','3577141','3577151','3577153','3577159','3577169','3577181','3577247','3577253','3577261','3577267','3577289','3577297','3577313','3577333','3577337','3577349','3577391','3577393','3577417','3577459','3577487','3577501','3577507','3577513','3577517','3577543','3577571','3577573','3577577','3577597','3577631','3577649','3577661','3577663','3577669','3577699','3577703','3577727','3577771','3577793','3577799','3577829','3577859','3577877','3577891','3577897','3577907','3577913','3577921','3577957','3577961','3577963','3577967','3577997','3578017','3578021','3578033','3578053','3578059','3578089','3578093','3578101','3578119','3578129','3578131','3578149','3578167','3578191','3578203','3578209','3578221','3578227','3578231','3578243','3578249','3578257','3578261','3578273','3578293','3578353','3578359','3578383','3578437','3578453','3578461','3578467','3578473','3578539','3578543','3578567','3578569','3578573','3578581','3578591','3578599','3578633','3578651','3578657','3578681','3578683','3578693','3578717','3578723','3578737','3578741','3578759','3578791','3578801','3578807','3578819','3578837','3578843','3578863','3578873','3578879','3578893','3578903','3578917','3578947','3578951','3578969','3578989','3579071','3579077','3579083','3579089','3579119','3579127','3579133','3579139','3579157','3579161','3579179','3579187','3579211','3579221','3579271','3579281','3579287','3579347','3579349','3579371','3579377','3579403','3579481','3579487','3579493','3579497','3579509','3579523','3579529','3579533','3579547','3579551','3579613','3579623','3579629','3579647','3579649','3579679','3579683','3579691','3579703','3579761','3579767','3579769','3579799','3579803','3579817','3579827','3579841','3579857','3579859','3579869','3579871','3579893','3579931','3579949','3579959','3580001','3580067','3580069','3580091','3580103','3580123','3580127','3580133','3580141','3580153','3580163','3580169','3580207','3580211','3580229','3580259','3580261','3580271','3580289','3580301','3580331','3580333','3580337','3580351','3580363','3580373','3580393','3580397','3580403','3580411','3580429','3580441','3580457','3580463','3580487','3580513','3580519','3580553','3580579','3580583','3580597','3580609','3580613','3580649','3580657','3580669','3580673','3580679','3580691','3580697','3580747','3580751','3580763','3580771','3580793','3580807','3580813','3580831','3580849','3580859','3580861','3580901','3580909','3580919','3580943','3580957','3580963','3581003','3581021','3581029','3581041','3581047','3581087','3581099','3581107','3581113','3581117','3581129','3581131','3581153','3581167','3581189','3581191','3581219','3581251','3581257','3581269','3581293','3581321','3581363','3581377','3581381','3581393','3581419','3581429','3581467','3581497','3581503','3581507','3581521','3581549','3581551','3581579','3581593','3581597','3581609','3581621','3581639']
@kbchars = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9","~","`","!","@","#","$","%","^","&","*","(",")","-","_","=","+","[","]","{","}",";",":","\"","'","\\","/","|","?","<",">",",","."," ","\t","\n"]
@chbytes = [] ## here we will just convert them to bytes, we want them to all be numbers below 100 and above 0
@kbchars.each do |ch|
if @host_os == "mingw32"
@chbytes << ch.bytes[0].to_s
elsif @host_os == "linux"
@chbytes << ch.to_java_bytes[0].to_s
end
end
@alphnumdex = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9"]
@alphdex = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
@alphdexl = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
@alphdexu = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
@symdex = ["`","~","!","@","#","$","%","^","&","*","(",")","_","-","=","+","[","]","{","}","\\","|","/","<",">",".",",",";",":","'",'"'," ", " "]
@numdex = ['0','1','2','3','4','5','6','7','8','9']
@vowels = ['a','e','i','o','u']
@doublevowels = ['ee','ae','oe','uu','iu','oo','aa']
@consonants = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z']
@doubleconsonants = ['bl','br','cl','cr','dr','fr','ft','fl','gr','gl','gn','nd','ld','ll','pl','pr','sl','sn','sp','ss','rl','rn','rt','rr','rd','st','nt','rm','mm','xp']
def splice(bstr,estr,inpstr)
str1_markerstring = bstr.to_s
str2_markerstring = estr.to_s
return inpstr[/#{str1_markerstring}(.*?)#{str2_markerstring}/m, 1]
end
def rands(digits)
if digits.to_i < 5
key = rand(10**8..10**9).to_s(36).to_S[0..digits.to_i].to_s
else
key = ""
digits.times do
key << rand(10**8..10**9).to_s(36).to_s[rand(6).to_i].to_s
end
end
return key.to_s
end
def numeric?(s) ## check if a string has only positive integers
return s !~ /\D/
end
def fnum(n) ## puts commas into large numbers and returns as strings but does nothing to them if three or less digits
str = ''
s = n.to_s.split("").reverse
i=0
s.each do |nc|
if i == 2
i=0
str << nc.to_s + ","
else
str << nc.to_s
i+=1
end
end
if str.to_s[-1].to_s == ","
str = str.reverse.to_s.split("")[1..-1].join("").to_s
else
str = str.reverse.to_s
end
return str
end
def list_spacer(spaces,left,right) # (integer,array,array) makes a printable multi line list of the given labels and data w/ spacing, if you have more than two colums you can take the resulting string, divide its lines and repeat this method with a new colum for as many colums as youd like. does not include word length limits so not guareenteed to look nice if you have long strings in your lists, your spacing should account for maximum length
width = spaces .to_i+ 5
str = ''
left.each do |l|
spacer = ""
t = width - l.length.to_i
t.to_i.times { spacer << " " }
str << l.to_s + spacer.to_s + right[left.index(l)].to_s + "\n"
end
puts str.to_s
end
def numerize(str) # this will turn your strings into a list of positive numbers that never starts with 0, this is useful if you wish to perform an encryption algorithm on the string
ch_inds = []
str.to_s.split("").each do |ch|
ch_inds << @chbytes.index(ch.to_s.ord.to_s)
end
enc = []
ch_inds.each do |ch|
code = ch.to_i + 1
if code.to_s.length == 1
code = "0" + code.to_s
else
code = code.to_s
end
enc << code.to_s
end
enc = enc.join("").to_s
if enc.to_s[0].to_s == "0"
enc = enc[1..-1].to_s
end
return enc.to_s
end
def denumerize(str)
if str.to_s.length.odd?
str = "0" + str.to_s
end
str_codes = []
i = 0
hold = ""
str.to_s.split("").each do |num|
if i.to_i == 0
hold << num.to_s
i += 1
elsif i.to_i == 1
hold << num.to_s
i = 0
str_codes << hold.to_s
hold = ""
end
end
str = str_codes
str_codes = []
str.each do |c|
str_codes << c.to_i - 1
end
dec_str = ""
str_codes.each do |c|
dec_str << @kbchars[c.to_i].to_s
end
return dec_str.to_s
end
def encode(str,key)
if RbConfig::CONFIG["host_os"] == "mingw32" ##this way in windows
key = []
@kbchars.each { |ch| key << ch.to_s.bytes[0].to_s }
elsif RbConfig::CONFIG["host_os"] == "linux" ## this way on android and linux
key = []
@kbchars.each do |ch|
key << ch.to_s.to_java_bytes[0].to_s
end
end
str = str.to_s.split("") ## first we split the given string into an array of character strings
bytes = [] ## the bytes will go here
str.each do |ch| ## so first step is to get a list of the bytes of each character
if RbConfig::CONFIG["host_os"] == "mingw32"
bytes << ch.to_s.bytes[0].to_s
elsif RbConfig::CONFIG["host_os"] == "linux"
bytes << ch.to_s.to_java_bytes[0].to_s
end
end
tablea = []
bytes.each do |b| ## the second step is to turn the bytes into index numbers determined by the order of the key
tablea << key.index(b.to_s).to_i
end
tableb = []
tablea.each do |c| ## the third step is to add 2 to each index value to eliminate the 0 values
tableb << c.to_i + 2
end
tablec = []
i = 2
tableb.each do |c| ## each character index is now multiplied by a number relative to its position in the string
tablec << c.to_i * i.to_i
i += 1
end
t = tablec.join("334455").to_s ## now we use the smallest yet least likley number to occur, some keys might give issues and others not, this will be a big area for improvements
return t.to_i * 2 ## final step is multiplying the result data one more time, to mask the 334455 seperators we used to join the characters
end
def decode(str,key)
if RbConfig::CONFIG["host_os"] == "mingw32" ##this way in windows
key = []
@kbchars.each { |ch| key << ch.to_s.bytes[0].to_s }
elsif RbConfig::CONFIG["host_os"] == "linux" ## this way on android and linux
key = []
@kbchars.each do |ch|
key << ch.to_s.bytes.to_s
end
end
str = str.to_i / 2
str = str.to_s.split("334455")
i = 2
tableb = []
str.each do |c|
tableb << c.to_i / i.to_i
i += 1
end
tablea = []
tableb.each do |c|
tablea << c.to_i - 2
end
bytes = []
tablea.each do |c|
bytes << key[c.to_i].to_s
end
str = []
bytes.each do |byte|
str << byte.to_i.chr.to_s
end
return str.join("").to_s
end
def exponate(n) ## take the given number and search for exponets which would result in it
c=2
e=2
r = [0,0]
until c > n
e = 2
until e >= n
if c**e == n
return [c,e]
end
e += 1
end
c += 1
end
end
def factors(n) ## get two numbers that multiplied together would result in the given value
p = [2]
vn = 2
until vn == n
vn += 1
p << vn
end
p.delete_at(-1)
f1 = 0
f2 = 0
pd = []
p.each do |pn|
s = n.to_f / pn.to_f
if s.to_s[-2..-1].to_s == ".0"
pd << pn
end
end
pd.each do |p|
if p * p == n
f1, f2 = p, p
else
cd = pd
cd.delete(p)
cd.each do |pr|
if p * pr == n
f1, f2 = p, pr
break
end
end
end
end
return [f1,f2]
end
def map_directory(dir) ## returns all subfolder and file paths inside the given directory [folders Array,files Array]
files = []
subdirectories = []
remaining_directories = [dir.to_s]
until remaining_directories.length.to_i == 0
cd = remaining_directories[0]
begin
Dir.foreach(cd) do |d|
if d.to_s != "." and d.to_s != ".."
if File.file?(cd.to_s + "/" + d.to_s)
files << cd.to_s + "/" + d.to_s
elsif File.directory?(cd.to_s + "/" + d.to_s)
subdirectories << cd.to_s + "/" + d.to_s
remaining_directories << cd.to_s + "/" + d.to_s
end
end
end
rescue
## subdirectory unaccessable, cant be includded with the rest of the mapping, is included as an unmapped directory which will appear empty
end
remaining_directories.delete_at(0)
end
return [subdirectories,files] ##this array of two arrays will be considered a mapping
end
def directory_bytes(dir) ## measure the contents of all file in the given directory and its subdirectories
files = []
subdirectories = []
remaining_directories = [dir.to_s]
until remaining_directories.length.to_i == 0
cd = remaining_directories[0]
begin
Dir.foreach(cd) do |d|
if d.to_s != "." and d.to_s != ".."
if File.file?(cd.to_s + "/" + d.to_s)
files << cd.to_s + "/" + d.to_s
elsif File.directory?(cd.to_s + "/" + d.to_s)
remaining_directories << cd.to_s + "/" + d.to_s
end
end
end
rescue
##access denied error will go on silently in the background as it is skipped from the measurement
end
remaining_directories.delete_at(0)
end
size = 0
files.each do |f|
size += File.size(f).to_i
end
return size.to_i
end
def measure_directory(dir) ## my older and slower version of the method above, no permission denial support
size = 0
files = 0
subdirectories = 0
remaining_directories = []
if dir.is_a? String
remaining_directories << dir.to_s
elsif dir.is_a? Array
dir.each do |d|
remaining_directories << d.to_s
end
end
until remaining_directories.length.to_i == 0
cd = remaining_directories[0]
remaining_directories.delete_at(0)
Dir.foreach(cd) do |d|
if d.to_s != "." and d.to_s != ".." and d.to_s != "..."
if File.file?(dir.to_s + "/" + d.to_s)
files += 1
size += File.size(dir.to_s + "/" + d.to_s).to_i
elsif File.directory?(dir.to_s + "/" + d.to_s)
subdirectories += 1
remaining_directories < dir.to_s + "/" + d.to_s
end
end
end
end
return [size.to_i,subdirectories.to_i,fi]
end
def env
puts "############ Instance Variables ############"
puts ""
puts " - " + instance_variables.join("\n - ")
puts ""
puts "################ Methods ###################"
puts ""
puts " - splice(bstr,estr,mstr)"
puts " - rands(length)"
puts " - numeric?(str)"
puts " - fnum(str)"
puts " - list_spacer(spaces,left,right)"
puts " - numerize(str)"
puts " - denumerize(str)"
puts " - encode(str,key)"
puts " - decode(str,key)"
puts " - map_dir(p)"
puts " - dir_bytes(p)"
puts " - eval_dir(p)"
puts " - exponate(n)"
puts " - factors(n)"
puts ""
puts "############################################"
end
puts "Greetings Dev, enter 'env' for info about this ruby environment."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment