Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Decrypt a File *Blowfish* (See related posts)

// A simple ruby script to decrypt a file

#
#   A simple ruby script to decrypt a file
#     can be edited to decrypt directories also
#
#    Written by:  steve at pentest.it
#                 www.pentest.it
#
#    Using the blowfish algorithm
#         several algorithms exist, just substitute for 'blowfish'
#         make sure it matches the encryption algorithm
require 'crypt/blowfish'

begin
#take in the file name to decrypt as an argument
  filename = ARGV.shift
  puts "Decrypting #{filename}"
  p = "Decrypted_#{filename}"
#User specifies the original key from 1-56 bytes (or guesses)
  print 'Enter your encryption key: '
  kee = gets
#initialize the decryption method using the user input key  
  blowfish = Crypt::Blowfish.new(kee)
  blowfish.decrypt_file(filename.to_str, p)
#decrypt the file  
  puts 'Decryption SUCCESS!'
rescue
#if the script busts for any reason this will catch it
  puts "\n\n\nSorry the decryption was unsuccessful"
  puts "USAGE: ruby decryption.rb <span class="escape">\n\n\n</span></span><span class="punct">"</span>
  <span class="keyword">raise</span>
<span class="keyword">end</span>
</pre>
        </div>
        <div class="post-metadata">
          to <a href="/tag/ruby" class="tag">ruby</a> by <a href="/user/studlee2">studlee2</a> on Sat Jul 08 03:16:00 +0000 2006
        </div>
<br>
      </div>
    </div>
<a name="comments" id="comments"></a>
    <p>You need to <a href="/account/signup">create an account</a> or log in to post comments to this site.</p>
<br>
    <a name="related" id="related"></a>
    <div class="box green">
      <h3>Related Posts</h3>
      <div id="related-posts">
        <p>» <a href="/posts/show/6">Typo under lighttpd</a> <span class="post-metadata">in <a href="/tag/lighttpd" class="tag">lighttpd</a> <a href="/tag/ruby" class="tag">ruby</a> <a href="/tag/rails" class="tag">rails</a> <a href="/tag/typo" class="tag">typo</a> <a href="/tag/ruby-fcgi" class="tag">ruby-fcgi</a></span><br>
        » <a href="/posts/show/16">password hash script</a> <span class="post-metadata">in <a href="/tag/ruby" class="tag">ruby</a> <a href="/tag/password" class="tag">password</a></span><br>
        » <a href="/posts/show/19">Stable sort</a> <span class="post-metadata">in <a href="/tag/ruby" class="tag">ruby</a> <a href="/tag/sort" class="tag">sort</a></span><br>
        » <a href="/posts/show/588">date time in ruby</a> <span class="post-metadata">in <a href="/tag/ruby" class="tag">ruby</a> <a href="/tag/time" class="tag">time</a> <a href="/tag/date" class="tag">date</a></span><br>
        » <a href="/posts/show/46">rip calendar attachments from an email (in ruby)..</a> <span class="post-metadata">in <a href="/tag/email" class="tag">email</a> <a href="/tag/ruby" class="tag">ruby</a> <a href="/tag/calendar" class="tag">calendar</a></span><br>
        » <a href="/posts/show/738">count characters</a> <span class="post-metadata">in <a href="/tag/ruby" class="tag">ruby</a> <a href="/tag/count" class="tag">count</a></span><br></p>
      </div>
    </div>
<br style="clear: both">
    <div id="footer">
      <p>Snippets (<a href="#">source code soon to be available</a>) developed by Peter Cooper and powered by Ruby On Rails</p>
    </div>
  </div>
</body>
</html>