Skip to content

Instantly share code, notes, and snippets.

@Ninjex
Ninjex / lookup.rb
Last active August 29, 2015 13:56
MD5 Lookup Table Generator
#!/usr/bin/ruby
require 'digest/md5' # Hashing strings to MD5
if ARGV[0] != '-i' || ARGV[2] != '-o' || ARGV[3].nil?
puts "Syntax Error!"
puts "Usage: ruby lookup.rb -i <input file> -o <output file>"
else
input_file = ARGV[1]
if File.exist?(input_file)
output_file = ARGV[3]
text = File.open(input_file).read
@Ninjex
Ninjex / gist:9048279
Last active August 29, 2015 13:56 — forked from Amazingred/gist:4104717
#!/usr/bin/env ruby
# Ruby script to generate SSHA (Good for LDAP)
require 'digest/sha1'
require 'base64'
# The output in hash will never have trailing whitespace, removed .chomp!
hash = Base64.encode64(Digest::SHA1.digest(#{pass}#{salt}#{salt}))
# Use string interpolation, no need to add \n puts does this for you
puts "userPassword: #{hash}"
@Ninjex
Ninjex / fizzbuzz.rb
Last active August 29, 2015 13:56
FizzBuzz with classes
class Enumerator::Lazy
def filter_map
Lazy.new(self) do |holder, *values|
result = yield *values
holder << result if result
end
end
end
class Fizz
@Ninjex
Ninjex / hailstorm.rb
Created February 27, 2014 15:32
Hailstorm Function
#!/usr/bin/ruby
def hailstorm n
vals = [n]
while n > 1 and n = (n.even?) ? (n/2) : (3 * n + 1)
vals << n
end
p vals # List returns
end
hailstorm(27)
@Ninjex
Ninjex / stego.rb
Created February 28, 2014 16:20
This script will take text and embed it into a picture via tampering with pixel LSB values.
#!/usr/bin/ruby
require 'rubygems'
require 'RMagick'
prompt = '> '
puts "Image to embed (not overwritten):"
print prompt
image_file = gets.chomp
img = Magick::Image::read(image_file)[0]
width = img.columns
height = img.rows
@Ninjex
Ninjex / exec.rb
Created March 10, 2014 19:31
A Weechat plugin coded in Ruby. This plugin allows you to run command on your machine from IRC, additionally you may choose to directly post the messages to all users in IRC with the -p option. For example: /exec -p echo 'hi'
#!/usr/bin/ruby
def weechat_init
Weechat.register('exec', 'Ninjex', '1.0', 'GPL3', 'Execute a terminal command via /exec <command>', '', '')
Weechat.hook_command('exec', 'Execute a terminal command from chat', '', '', '', 'exec', '')
return Weechat::WEECHAT_RC_OK
end
def exec(data, buffer, args)
to = nil
buffer = Weechat.current_buffer
@Ninjex
Ninjex / short_url.rb
Last active August 29, 2015 13:57
A Weechat plugin for shortening long URL's. This script uses the URL shortening application at hts.io
#!/usr/bin/ruby
# Need to add a validation check on URL's -- just don't be ignorant with it :D
require 'mechanize' # Necessary to communicate with the server.
def weechat_init
Weechat.register('short_url', 'Ninjex', '1.0', 'GPL3', 'Shorten a URL /short_url <link>', '', '')
Weechat.hook_command('short_url', 'Shorten URL /short_url <link>', '', '', '', 'short_url', '')
return Weechat::WEECHAT_RC_OK
end
def short_url(data, buffer, args)
@Ninjex
Ninjex / sql.rb
Created March 17, 2014 15:07
Query a MySQL database from within Weechat. Ruby plugin
#!/usr/bin/ruby
# Required packages / gems
# libmysql-ruby libmysqlclient-dev
# gem mysql2
require 'mysql2'
@options = {
"public" => "false", # MySQL query result publicly visible
"host" => "localhost", # MySQL host
"user" => "root", # MySQL username
@Ninjex
Ninjex / substitute.rb
Created March 17, 2014 16:26
Substitute character values in a password file, generating new strings. Save to the desired file. -- Not very efficient
#!/usr/bin/ruby
@convert = {
"e" => ["e", "3"], "l" => ["l", "1"], "o" => ["o", "0"],
"a" => ["a", "4"], "t" => ["t", "7"], "s" => ["s", "5", "$"],
"c" => ["c", "("], "g" => ["g", "6"], "p" => ["p", "9"],
"b" => ["b", "8"]
}
@arrays = @convert.values # Grab all arrays in the hash
@Ninjex
Ninjex / main.rb
Created April 28, 2014 15:29
Hellbound Hackers Timed Challenge 4
#!/usr/bin/ruby
require 'mechanize'
require 'io/console'
def decrypt(str)
final = []
for i in (0..str.length)
i.odd? ? final << str[i-2] : final << str[i]
end