-
Notifications
You must be signed in to change notification settings - Fork 0
/
locale.d
173 lines (125 loc) · 5.64 KB
/
locale.d
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
Copyright (C) 2011-2016 Mario Cianciolo <[email protected]>
This file is part of playfair.
playfair 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.
playfair 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 playfair. If not, see <http://www.gnu.org/licenses/>.
*/
module playfair.locale;
import std.stdio, std.string, std.cstream;
bool ansi_terminal = true; // enables ANSI escape sequences
void WriteFormattedString(char[] str, char[] arg="") {
char[] s = str;
s = replace(s,"$APPNAME", "Playfair");
s = replace(s,"$BINARY_P", "playfair");
s = replace(s,"$BINARY", "[b]playfair[/]");
s = replace(s,"$AUTHOR", "Salvatore Udda");
s = replace(s,"$VERSION", "0.7");
s = replace(s,"$EMAIL", "[email protected]");
s = replace(s,"$ARG", arg);
if (ansi_terminal) {
s = replace(s,"[b]","\033[1m");
s = replace(s,"[u]","\033[4m");
s = replace(s,"[-]","\033[7m");
s = replace(s,"[/]","\033[0m");
} else {
s = replace(s,"[b]","");
s = replace(s,"[u]","");
s = replace(s,"[-]","");
s = replace(s,"[/]","");
}
derr.writef(s);
}
const char[] help_str = "
[u][b]SINTAX[/]
$BINARY -e [u]chiave[/] [u]testo[/]
$BINARY --encode [u]chiave[/] [u]testo[/]
Encodes input text using specified key.
$BINARY -d [u]chiave[/] [u]testo[/]
$BINARY --decode [u]chiave[/] [u]testo[/]
Decodes input text using specified key. Parses decoded text and removes
extra characters (X, Q) probably inserted to separate twin letters.
$BINARY -r [u]chiave[/] [u]testo[/]
$BINARY --rawdecode [u]chiave[/] [u]testo[/]
Decodes input text using specified key. Does not modify decoded text.
Useful if you think the original message contains 'X's that were
removed in --decode mode.
$BINARY -m [u]chiave[/]
$BINARY --matrix [u]chiave[/]
Views the matrix correspondinf to specified key.
$BINARY -v
$BINARY --version
Views version notes.
$BINARY -?
$BINARY --help
Views this help.
The only mandatory argument is the first one (execution mode). If one or
more arguments are not specified, they will be asked at runtime.
[b]A B C D E[/]
[b]F G H I K[/] This is standard matrix, used if input key is a
[b]L M N O P[/] empty string ([b]\"\"[/]). Remember to enclose
[b]Q R S T U[/] your key and text in double quotes ([b]\"[/]).
[b]V W X Y Z[/]
[u][b]KEY MODIFIERS[/]
Several special characters can be put before the key to alter the placing
of the letters in the matrix:
[b]>[/] (Offset +)
Every occurence of this character makes the matrix shift one place
forward. Letters in the matrix are like into a circular queue, so
places left empty by shifted letters will be occupied by the last
letters of the matrix. E.g: in [u]>>chiave[/] 'C' will be the third
character, while the first will be 'Y'.
[b]<[/] (Offset -)
Every occurence of this character makes the matrix shift one place
backward. Letters in the matrix are like into a circular queue, so
places left empty by shifted letters will be occupied by the first
letters of the matrix. E.g: in [u]<<chiave[/] 'A' will be the first
character, while 'C' will be the 23rd.
[b]@[/] (Spiral)
Letters in the matrix will be placed clockwise in a spiral shape,
instead of default. Starting point is upper left corner, but can be
changed using [b]<[/] and [b]>[/] modifiers.
[b]:[/] (Reverse)
Reverse order of letters of the matrix. Letters will be places from
last to first in case of row-by-row placement, and in case of spiral
placement they will be placed from center to upper left corner.
[b]-[/] (Invert)
Inverts direction of placement of letters into the matrix. Letters
will be placed right-to-left in case of row-by-row placement, and in
case of spiral placement they will be placed counterclockwise.
[b]X W U T S[/]
[b]R P E V Q[/] Example matrix generated by the key
[b]O Z Y A N[/] [u]-<>>@<>>chiaveprova[/]: spiral starting from
[b]B C H I M[/] center, with +2 offset
[b]D F G K L[/]
To view the matrix generated from a key, run $BINARY -m [u]key[/]
[u][b]EXIT CODE[/]
Application returns [b]0[/] if the command is executed successfully, and
returns [b]1[/] in case of errors in command line.
[u][b]INFORMAZIONI[/]
Author: $AUTHOR
$EMAIL
Informations about Playfair cipher:
https://en.wikipedia.org/wiki/Playfair_cipher
";
const char[] choice_str = "
$APPNAME $VERSION
1. Encode plain text
2. Decode ciphered text
3. Decode ciphered text (raw mode, keep 'X's)
4. View matrix generated by a key
5. View version notes
6. View help
Insert a number [1-6]: ";
const char[] invalidchoice_str = "Invalid choice. Insert a number [1-6]: ";
const char[] version_str = "$APPNAME version $VERSION by $AUTHOR <$EMAIL>\n";
const char[] unrecognized_option_str = "\"$ARG\": unrecognized option.\nType $BINARY_P -? for help.\n";
const char[] insertkey_str = "Insert key: ";
const char[] inserttxt_str = "Insert message to parse and press Enter.\n";