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
| def decode(to_decode,match_results) | |
| match_results.each do |a,b| | |
| decrypted = decrypt(((b.ord-a.ord).abs),to_decode) | |
| decrypted.language == :english ? (return decrypted) : decrypted | |
| end | |
| end |
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
| def match_char(hash_results) | |
| dist,dist_c,match_hash = 100,"",Hash.new | |
| hash_results.each { |a,b| @gen_char_freq.each { |c,d| dist,dist_c = (d-b).abs, c if (d-b).abs < dist} | |
| match_hash[a],dist = dist_c,100} | |
| return match_hash | |
| end |
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
| speed_dial = SpeedDialPermutations.new | |
| puts speed_dial.get_combinations( ["Up","Right","Left","Down"]) | |
| # Up,Up,Up,Right (etc.) | |
| puts speed_dial.simulate( ["Up","Right","Left","Down"],0.01,6) | |
| # Attempt 3 Unsuccessful : Up,Left,Down,Left : Elapsed time : 8.000366121 (etc.) | |
| puts speed_dial.average_time( ["Up","Right","Left","Down"],10000,["Up","Down","Left","Right"]) | |
| #8.534266573342666 |
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
| function simple_postfix(input){ | |
| val = input.split(' '); | |
| return eval(val[0] + val[2] + val[1]); | |
| } | |
| console.log("Result is : " + simple_postfix("4 2 +")); |
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
| def freq_analysis_first(msg) | |
| f_freq,msg_arr,sum = Hash.new(0),msg.split(' '),0 | |
| msg_arr.each {|i| i.split('').each_with_index do |a,b| | |
| f_freq[a], sum = f_freq[a] + 1, sum +1 if b == 0 | |
| end} | |
| return f_freq.each {|a,b| f_freq[a] = calc_perc(b,sum)}.sort_by {|i,j| j}.reverse | |
| end |
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
| def encrypt_single_key(key,value) | |
| offset,encrypted, off_i = key,[] , 1 | |
| value.split('').each_with_index do |val, i| | |
| val.ord >= 97 && val.ord <= 122 ? dist = val.ord - (offset % 26) : dist = val.ord | |
| dist < 97 && dist != val.ord ? (encrypted.push (122 - (97 - (dist+1))).chr) : (encrypted.push dist.chr) | |
| end | |
| return encrypted.join | |
| end |
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
| def decrypt_single_key(key,value) | |
| offset,decrypted, off_i = key,[] , 1 | |
| value.split('').each_with_index do |val, i| | |
| val.ord >= 97 && val.ord <= 122 ? dist = (val.ord + offset % 26) : dist = val.ord | |
| dist > 122 && dist!= val.ord ? (decrypted.push (122 - (26 - (dist - 122))).chr) : (decrypted.push dist.chr) | |
| end | |
| return decrypted.join | |
| end |
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
| def freq_analysis(msg) | |
| freq,msg_arr,sum = Hash.new(0),msg.split(''),0 | |
| msg_arr.each_with_index {|i,j| msg_arr.delete_at(j) if i == " "}.each {|i| freq[i],sum = freq[i] + 1,sum +1} | |
| return freq.each {|a,b| freq[a] = calc_perc(b,sum)}.sort_by {|i,j| j}.reverse | |
| end |
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
| class BabyCrypto | |
| def decrypt(key, value) | |
| ((key.class == Fixnum) || (key.to_i != 0)) ? offset = key.to_s.split.map {|i| i.to_i} : offset = calc_offset(key) | |
| decrypted, off_i = [], 1 | |
| value.split('').each_with_index do |val, i| | |
| val.ord >= 97 && val.ord <= 122 ? dist = val.ord + (offset[off_i -1] % 26) : dist = val.ord | |
| dist > 122 && dist!= val.ord ? (decrypted.push (122 - (26 - (dist - 122))).chr) : (decrypted.push dist.chr) | |
| off_i % (offset.length) == 0 ? off_i = 1 : off_i = off_i + 1 | |
| end |
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
| class SpeedDialPermutations | |
| def average_time(set,iterations,perm,target = get_combinations(set).sample) | |
| avg_arr = [] | |
| for i in 0..iterations | |
| avg_arr.push get_combinations(set).shuffle.index(target) | |
| end | |
| return ((avg_arr.inject(:+).to_f / avg_arr.size)*4)/60 | |
| end |