-
Notifications
You must be signed in to change notification settings - Fork 0
/
Secrets.pas
138 lines (122 loc) · 3.35 KB
/
Secrets.pas
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
Unit Secrets;
Interface
Uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.Actions, Vcl.ActnList, System.IOUtils,
Vcl.StdCtrls;
Type
TSecretForm = class(TForm)
SecretMemo: TMemo;
SecretActionList: TActionList;
aStartupConfiguration: TAction;
aCloseActions: TAction;
Procedure aStartupConfigurationExecute(Sender: TObject);
Procedure FormActivate(Sender: TObject);
Procedure FormResize(Sender: TObject);
Procedure FormClose(Sender: TObject; var Action: TCloseAction);
Private
{ Private declarations }
Public
{ Public declarations }
End;
Var
SecretForm: TSecretForm;
Implementation
Const
FILE_SECRETS: String = '\ReMind\secrets.dat';
{$R *.dfm}
Function DecodeLine(Line: String) : String;
Var
I, Secret: Integer;
TempNumStr: String;
Begin
I := 1;
Result := '';
TempNumStr := '';
While I <= Length(Line) do
Begin
If Line[I] = ' ' then
Begin
Secret := StrToInt(TempNumStr);
Secret := Secret xor 7;
Secret := Secret + 2;
Result := Result + Chr(Secret);
Inc(I);
TempNumStr := '';
End
Else If (Line[I] in ['0'..'9']) then
Begin
TempNumStr := TempNumStr + Line[I];
Inc(I);
End;
End;
End;
Procedure AddFileDataToMemo(NotesMemo: TMemo);
Var
FSecrets: TextFile;
Temp: String;
Begin
AssignFile(FSecrets, TPath.GetDocumentsPath + FILE_SECRETS);
Reset(FSecrets);
ReadLn(FSecrets, Temp);
While not EoF(FSecrets) do
Begin
ReadLn(FSecrets, Temp);
Temp := DecodeLine(Temp);
NotesMemo.Lines.Add(Temp);
End;
System.Close(FSecrets);
End;
Procedure TSecretForm.aStartupConfigurationExecute(Sender: TObject);
Begin
SecretMemo.Clear;
AddFileDataToMemo(SecretMemo);
End;
Procedure TSecretForm.FormActivate(Sender: TObject);
Begin
SecretMemo.Width := Self.ClientWidth;
SecretMemo.Height := Self.ClientHeight;
End;
Function EncryptedLine(Line: String) : String;
Var
I, Secret: Integer;
Begin
Result := '';
For I := 1 to Length(Line) do
Begin
Secret := Ord(Line[I]) - 2;
Secret := Secret Xor 7;
Result := Result + IntToStr(Secret) + ' ';
End;
End;
Procedure SaveMemoData(SecretMemo: TMemo);
Var
FSecrets: TextFile;
I: Integer;
PasswordLine: String;
Begin
AssignFile(FSecrets, TPath.GetDocumentsPath + FILE_SECRETS);
Reset(FSecrets);
ReadLn(FSecrets, PasswordLine);
Close(FSecrets);
AssignFile(FSecrets, TPath.GetDocumentsPath + FILE_SECRETS);
Rewrite(FSecrets);
Writeln(FSecrets, PasswordLine);
For I := 0 to SecretMemo.Lines.Count - 1 do
Begin
WriteLn(FSecrets, EncryptedLine(SecretMemo.Lines[I]));
End;
Close(FSecrets);
End;
Procedure TSecretForm.FormClose(Sender: TObject; var Action: TCloseAction);
Begin
SaveMemoData(SecretMemo);
SecretMemo.Clear;
Self.Close;
End;
Procedure TSecretForm.FormResize(Sender: TObject);
Begin
SecretMemo.Width := Self.ClientWidth;
SecretMemo.Height := Self.ClientHeight;
End;
end.