-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathROT.ps1
140 lines (127 loc) · 3.54 KB
/
ROT.ps1
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
#ROT encryption rotation
#Numbers and symbols are allowed but not rotated in any way
$Alphabet = @("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z")
$Alphabet = $Alphabet.split(",")
Clear-Host
#Functions
Function AskOp {
do {
Clear-Host
Write-Host ""
$Op = Read-Host -Prompt "Select option 1 or 2:
1. Encrypt
2. Decrypt
Option"
if ($Op -ne 1 -and $Op -ne 2) {
Write-Host ""
Write-Host -ForegroundColor Red "Type '1' or '2'"
Write-Host
Pause
}
} until ($Op -eq 1 -or $Op -eq 2)
$Op
return
}
Function RotPrompt {
#You can change the number of rotations to something other than the traditional 13
Write-Host ""
$RotRotation = Read-Host "Number of rotations"
$RotRotation
return
}
Function GetMessage {
Write-Host ""
if ($Op -eq 1) {
$Message = Read-Host -Prompt "Enter message to encrypt"
}
if ($Op -eq 2) {
$Message = Read-Host -Prompt "Enter message to decrypt"
}
$Message = $Message.ToUpper()
$MessageSplit = $Message -split ""
$MessageSplit = $MessageSplit | Select-Object -Skip 1
$MessageSplit = $MessageSplit | Select-Object -SkipLast 1
$MessageSplit
return
}
Function Encryption {
$NewMessage = @()
Foreach ($Letter in $Message) {
$LetterIndex = $Alphabet.IndexOf($Letter)
if (($Letter -notin 0..9) -and ($Letter -notin $Alphabet)) {
$NewLetter = $Letter
$NewMessage += $NewLetter
continue
}
if ($Letter -match " ") {
$NewLetter = " "
$NewMessage += $NewLetter
continue
}
if ($Letter -in 0..9) {
$NewLetter = $Letter
$NewMessage += $NewLetter
continue
}
if (($LetterIndex + $RotRotation) -gt 26) {
$OverLetterIndex = ($LetterIndex + $RotRotation) - 26
$NewLetter = $Alphabet[$OverLetterIndex]
$NewMessage += $NewLetter
} else {
$NewLetter = $Alphabet[$LetterIndex + $RotRotation]
$NewMessage += $NewLetter
}
}
$NewMessage = $NewMessage -join ""
$NewMessage
return
}
Function Decryption {
$NewMessage = @()
Foreach ($Letter in $Message) {
$LetterIndex = $Alphabet.IndexOf($Letter)
if (($Letter -notin 0..9) -and ($Letter -notin $Alphabet)) {
$NewLetter = $Letter
$NewMessage += $NewLetter
continue
}
if ($Letter -match " ") {
$NewLetter = " "
$NewMessage += $NewLetter
continue
}
if ($Letter -in 0..9) {
$NewLetter = $Letter
$NewMessage += $NewLetter
continue
}
if (($LetterIndex - $RotRotation) -lt 0) {
$OverLetterIndex = ($LetterIndex - $RotRotation) + 26
$NewLetter = $Alphabet[$OverLetterIndex]
$NewMessage += $NewLetter
} else {
$NewLetter = $Alphabet[$LetterIndex - $RotRotation]
$NewMessage += $NewLetter
}
}
$NewMessage = $NewMessage -join ""
$NewMessage
return
}
#Actions
$Op = AskOp
$RotRotation = RotPrompt
if ($Op -eq 1) {
$Message = GetMessage
$NewMessage = Encryption
Write-Host ""
$NewMessage
Write-Host ""
}
if ($Op -eq 2) {
$Message = GetMessage
$OriginalMessage = Decryption
Write-Host ""
$OriginalMessage
Write-Host ""
}