Sha256: b3ca3e60d88303fe6e8b58528323145abb3407e593b87be030dee1aa2ee70766
Contents?: true
Size: 1.69 KB
Versions: 5
Compression:
Stored size: 1.69 KB
Contents
=begin Ruby Number Station Author: David Kirwan https://gitub.com/davidkirwan Licence: GPL 3.0 NumberStation is a collection of utilities to aid in the running of a number station Copyright (C) 2018 David Kirwan This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. =end require "securerandom" require "json" require "time" module NumberStation def self.make_otp(pad_path, length, num_pads) path = pad_path || Dir.pwd len = length || 250 num = num_pads || 5 NumberStation.log.debug "make_otp" pads = {} id = rand(0..99999).to_s.rjust(5, "0") file_name = File.join(path, "one_time_pad_#{id}.json") NumberStation.log.debug "file_name: #{file_name}" 0.upto(num.to_i - 1) do |i| pads[i] = { "key"=>SecureRandom.hex(len.to_i), "epoch_date"=>nil, "consumed"=>false } end one_time_pads = { :id=> id, :pads=> pads } unless File.file?(file_name) f = File.open(file_name, "w") f.write(one_time_pads.to_json) f.close else raise Exception.new("Exception #{file_name} already exists") end end end
Version data entries
5 entries across 5 versions & 1 rubygems