Created
July 2, 2012 01:27
-
-
Save fromheten/3030374 to your computer and use it in GitHub Desktop.
Dear diary - what is wrong?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/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