LoginSignup
0
0

More than 5 years have passed since last update.

文字列の一部をexampleにおきかえる

Last updated at Posted at 2016-12-12

AWSのドキュメントみてるとたまに遭遇するこういうやつ
http://docs.aws.amazon.com/ja_jp/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html

アクセスキー ID:AKIAIOSFODNN7EXAMPLE
シークレットアクセスキー: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

手順書とか書いてると,キーを発行したいけど自分のキーを手順書に載せるわけにはいかない..どうしよう,みたいな?

examplify.rb
#!/usr/bin/env ruby

word = ARGV[0] || STDIN.gets

exit if word.length <= 7

def gen_e
  [%w(e E 3), %w(x X), %w(a A), %w(m M), %w(p P), %w(l L 1), %w(e E 3),].map {|a| a.sample}.join
end

def gen_s(w)
  return w if w.length < 8
  if w.length < 14
    s = rand 1..w.length-7
    w.tap {|_| _.slice!(s, 7)}.insert(s, gen_e)
  end

  [gen_s(w[0...w.length/2]), gen_s(w[w.length/2..w.length])].join
end

puts gen_s(word.chomp)
uraura@rosemary$ echo abcdefghijklmnopqrstuvwxyz0123456789 | ./examplify.rb
abexAMpL3jkEXAMplEs3xAmple012EXAmpl3

置き換えすぎな気もするけど...まぁいいか...

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0