-
Notifications
You must be signed in to change notification settings - Fork 0
/
playing_with_passphrases.rb
35 lines (27 loc) · 1.2 KB
/
playing_with_passphrases.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def play_pass(str, n)
str.chars.map do |l|
if l =~ /[A-Za-z]/
ar = [l]
n.to_i.times { |x| ar << ar.last.next}
ar.last[-1]
elsif l =~ /\d/
9 - l.to_i
else
l
end
end.map.with_index { |x, i| i.odd? ? x.to_s.downcase : x }.reverse.join
end
# Everyone knows passphrases. One can choose passphrases from poems, songs, movies names and so on but frequently
# they can be guessed due to common cultural references. You can get your passphrases stronger by different means. One is the following:
# choose a text in capital letters including or not digits and non alphabetic characters,
# shift each letter by a given number but the transformed letter must be a letter (circular shift),
# replace each digit by its complement to 9,
# keep such as non alphabetic and non digit characters,
# downcase each letter in odd position, upcase each letter in even position (the first character is in position 0),
# reverse the whole result.
# Example:
# your text: "BORN IN 2015!", shift 1
# 1 + 2 + 3 -> "CPSO JO 7984!"
# 4 "CpSo jO 7984!"
# 5 "!4897 Oj oSpC"
# With longer passphrases it's better to have a small and easy program. Would you write it?