Skip to content

Instantly share code, notes, and snippets.

@ucnv
Created August 13, 2009 09:26
Show Gist options
  • Save ucnv/167060 to your computer and use it in GitHub Desktop.
Save ucnv/167060 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Test script for yet another JPEG glitch technique.
# Rewriting YCbCr Huffman table selectors in the JPEG header.
require 'erb'
data = File.open(ARGV.first) {|f| f.read }
sos = data.index "\xFF\xDA"
ns = data[sos + 4]
files = (4 ** ns).times.collect do |i|
sign = "%0#{2*ns}b" % i
ns.times do |j|
flag1 = (sign[j * 2] == 49) ? 0x10 : 0
flag2 = (sign[j * 2 + 1] == 49) ? 1 : 0
data[sos + 6 + j * 2] = flag1 | flag2
end
file = sign + '.jpg'
File.open(file, 'w') do |f|
f.print data
end
file
end
file = 'index.html'
File.open(file, 'w') do |f|
f.print ERB.new(DATA.read).result(binding)
end
`open #{file}`
__END__
<html>
<head><title>Rewrite SOS Glitch</title></head>
<body>
<% files.each do |i| %>
<img alt="<%= i %>" src="<%= i %>">
<% end %>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment