Skip to content

Instantly share code, notes, and snippets.

@fromheten
Created July 2, 2012 01:27
Show Gist options
  • Save fromheten/3030374 to your computer and use it in GitHub Desktop.
Save fromheten/3030374 to your computer and use it in GitHub Desktop.
Dear diary - what is wrong?
#/usr/bin/env ruby
# encoding: UTF-8
######
# Dear diary
# Created by Martin Josefsson, fromhet@github
# Licenced under the lastest GPL there is
######
require 'encryptor'
# Set up some global variables, in future versions theese will be easily editable for the user
# TODO let the user specify a diaryfile
$diaryfile = ".diary"
def new_entry
# Get text from ARGV
text = ARGV[0]
# "\n" + Time.now.to_s + Time.now.zone + "\n" +
# Encrypt it, faster stronger
encrypted_text = text.encrypt
# Write the encrypted text to the $diaryfile (default: ~/.diary
diary = File.open($diaryfile, 'a')
diary.write(encrypted_text + "\n")
# That is all, fokes! Close the diary.
diary.close
end
def decrypt
# Open the diary in read-mode
diary = File.open($diaryfile, 'r')
# Print the decrypted contents TODO make this sophisticated
puts diary.read.decrypt
# Close the diary file
diary.close
end
# Ask user for passphrase
puts "Enter the super-secret passphrase to lock your diary with"
passphrase = $stdin.gets.chomp
#Set standard settings
Encryptor.default_options.merge!(:algorithm => 'bf', :key => passphrase)
new_entry()
puts "\nDEBUG DECRYPT\n"
decrypt()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment