Skip to content

Instantly share code, notes, and snippets.

@glabra
Last active August 29, 2015 14:04
Show Gist options
  • Save glabra/5d5e1019d05ac27fae3a to your computer and use it in GitHub Desktop.
Save glabra/5d5e1019d05ac27fae3a to your computer and use it in GitHub Desktop.
earthquakeでLet's 難読化
=begin
/*****
encrypt.rb
*****/
様々な難読化をなしたうえでツイートするプラグインです。
Avaliable formats:
Base64, gzip, lzma, rot13, rot47
Dependeicies:
ruby-lzma
# 使用法
⚡ :encrypt FORMAT [$xx] TWEET
TWEETをFORMATの順に従ってencryptする。
$xxでreplyに変身する。
# FORMATの指定方法
","区切りで指定、左から順に解読される。
なお、指定するフォーマット名は下記の通りである。
base64: b64
base64(60文字毎に改行): b64n
gzip: gz
lzma: lz
rot13: r13
rot47(rot13の変種): r47
上記以外のフォーマット名は無視される。
=end
require "base64"
require "zlib"
require "lzma"
require "stringio"
Earthquake.init do
command :encrypt do |m|
data = m[1].split(" ")
format = data.shift.split(",")
if data[0].match(/^(\$[a-z]{2}|[0-9]+)$/)
reply_target = data.shift
else
reply_target = nil
end
tweet = data.join(" ")
encoded_text = encrypt(format, tweet)
if reply_target
input(":reply #{reply_target} #{encoded_text}")
else
input(encoded_text)
end
end
help :decrypt, "Obfuscationize tweet.", <<-HELP
⚡ :encrypt FORMAT [$xx] TWEET
FORMAT:
Base64: b64
Base64(60文字毎に改行): b64n
gzip: gz
lzma: lz
rot13: r13
rot47: r47
HELP
end
def encrypt(format, tweet)
retval = tweet
for fmt in format
case fmt
when "b64"
retval = encrypt_base64(retval, true)
when "b64n"
retval = encrypt_base64(retval, false)
when "gz"
retval = encrypt_gzip(retval)
when "lz"
retval = encrypt_lzma(retval)
when "r13"
retval = encrypt_rot13(retval)
when "r47"
retval = encrypt_rot47(retval)
end
end
return retval
end
def encrypt_base64(text_raw, flag_strict = true)
if flag_strict
return Base64.strict_encode64(text_raw)
else
return Base64.encode64(text_raw)
end
end
def encrypt_gzip(data_raw)
StringIO.open("", 'r+') do |io_str|
Zlib::GzipWriter.wrap(io_str) do |c_zlib|
c_zlib.write(data_raw)
end
return io_str.string
end
end
def encrypt_lzma(data_raw)
return LZMA.compress(data_raw)
end
def encrypt_rot13(da4a_raw)
return data_raw.tr("N-ZA-Mn-za-m", "A-Za-z")
end
def encrypt_rot47(data_raw)
return data_raw.tr("P-~!-O", "!-~")
end
# https://gist.github.com/glabra/5d5e1019d05ac27fae3a
@glabra
Copy link
Author

glabra commented Jul 25, 2014

gzオプションがまともなgzipを投げるようになった

@glabra
Copy link
Author

glabra commented Aug 2, 2014

返信できるようになった。誰も得しない。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment