Browse Source

rename files

master
Rafael Polo 8 years ago
parent
commit
a9c04a29ef
5 changed files with 0 additions and 171 deletions
  1. BIN
      cypherpunks.pdf.png
  2. BIN
      coffeescript/4.out.png
  3. +0
    -115
      data2png.rb
  4. +0
    -56
      flickr-alternative.rb
  5. BIN
      sample.png

BIN
cypherpunks.pdf.png View File

Before After
Width: 1083  |  Height: 1083  |  Size: 3.4 MiB

BIN
coffeescript/4.out.png View File

Before After
Width: 7  |  Height: 7  |  Size: 195 B

+ 0
- 115
data2png.rb View File

@ -1,115 +0,0 @@
require 'oily_png'
require 'base64'
require 'pry'
require 'zlib'
class String
def to_hex
self.unpack('H*')[0]
end
def from_hex
[self].pack('H*')
end
def to_b64
Base64.encode64(self)
end
def compact
Zlib::Deflate.deflate(self, Zlib::BEST_COMPRESSION)
end
end
def is_int?(x)
x % 1 == 0
end
def get_dimensions(size)
height = Math.sqrt(size)
unless is_int? height
width = size / height.ceil
unless is_int? width
width = width.floor
height = height.ceil + 1
end
else
width = height
end
[height.to_i, width.to_i]
end
def encode path
puts "Encoding #{path}..."
start = Time.now
data = File.read(path)
hex_encoded = data.to_b64.compact.to_hex
size = hex_encoded.size/6+1
dimension = get_dimensions(size)
puts dimension
height = dimension[0]
width = dimension[1]
puts "Pixels: #{size}"
puts "Dimension: #{height}x#{width}"
png = ChunkyPNG::Image.new(height, width)
x = y = count = 0
hex_encoded.scan(/.{1,6}/).each do |hexa_color|
printf("\r%d%", 100*(count+=1)/size+1)
# fill last pixel missing data
hexa_color = hexa_color + "0" * (6-hexa_color.size) if count>size-1 && hexa_color.size<6
png[x, y] = ChunkyPNG::Color.from_hex(hexa_color)
# compose
x += 1
if x>height-1
x = 0
y += 1
end
if y>width-1
y = 0
end
#puts "#{x}, #{y} = #{hexa_color}"
end
png.metadata['Author'] = 'ExtraPolo!'
png.metadata['Title'] = path
out_path = "#{path}.png"
png.save(out_path, :interlace => true)
original_size = data.size
out_size = File.read(out_path).size
puts ("-> encoded in %3.2f s" % [Time.now - start])
end
def decode path
puts "Decoding #{path}..."
start = Time.now
png = ChunkyPNG::Image.from_file(path)
pixels = png.pixels
size = pixels.size
hex_encoded = ''
count = 0
pixels.each do |p|
printf("\r%d%", 100*(count+=1)/size)
hex_encoded << ChunkyPNG::Color.to_hex(p)
end
puts
hex_encoded.gsub!('#', '')
puts hex_encoded
original_data = Base64.decode64(hex_encoded.from_hex)
original_title = png.metadata['Title']
File.open("out-#{original_title}", 'w'){|f| f.puts original_data}
puts ("-> decoded \"#{original_title}\" in %3.2f s" % [Time.now - start])
end
system "clear"
encode 'cypherpunks.pdf'
decode 'Ostrom - Governing the Commons - The Evolution of Institutions for Collective Action.pdf.png'

+ 0
- 56
flickr-alternative.rb View File

@ -1,56 +0,0 @@
# encoding: utf-8
# autor: Rafael Polo
# data: 18.08.2013
# Prova de Conceito: É possível utilizar os incríveis 1024 gigabytes de armazenamento de imagens
# do Flickr pra hospedar arquivos através de esteganografia nas imagens?
# esconde arquivo RAR em diversas imagens
def esteganografia(path)
out_path = "#{path}/out"
# cria pasta temporária
system("mkdir #{out_path}") unless File.directory? out_path
puts "Compactando..."
# Flickr tem o limite de 200MB por imagem, usarei 100MB por imagem.
system("rar a -v100m #{out_path}/out.rar #{path}")
# concateno RAR no fim do JPEG
system("mkdir #{out_path}/images")
Dir["#{out_path}/*.rar"].each do |chunk|
puts "Escondendo #{chunk}" # usa frame.jpg padrão
system "cat #{path}/frame.jpg #{chunk} > #{chunk}.jpg"
end
end
def upload_to_flickr
# por hora fiz manualmente o upload das imagens em um novo Set de uma novo Usuário
# http://www.flickr.com/photos/100332464@N03/sets/
return set_id || 72157635116479848
end
def get_from_set(set_id)
# uso API com key do novo usuário (poderia ser qualquer uma válida)
require 'flickraw' # 3
FlickRaw.api_key = '7fd9704ef650d1000263b1331277dd1'
FlickRaw.shared_secret = 'c9ee9d15766fcb0'
# pega as imagens das URLs de todas as imagens do Set dado
threads = []
flickr.photosets.getPhotos(:photoset_id => set_id).photo.each do |s|
chunk = FlickRaw.url_o flickr.photos.getInfo(:photo_id => s.id)
threads << Thread.new { system "wget #{chunk} -O #{s.title}" }
end
threads.each { |t| t.join }
system "unrar e -y out.part01.rar"
puts "Ok!"
end
# exemplo: cria 14 imagens distribuindo os 1.44 GB da pasta com o seguinte filme com legenda
esteganografia '/Users/polo/Downloads/Der.Himmel.Uber.Berlin.-.Wings.of.Desire.DVDRip.XviD.MakingOff.Org'
# sobe
set_id = upload_to_flickr
# remonta
get_from_set set_id

BIN
sample.png View File

Before After
Width: 519  |  Height: 518  |  Size: 591 KiB

Loading…
Cancel
Save