-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlib.swift
33 lines (29 loc) · 878 Bytes
/
lib.swift
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
/*================================
Use: "message".encrypt.decrypt
================================*/
import Foundation
extension String {
var encrypt: String {
func zeroPad(_ bin: String) -> String {
return "00000000".prefix(8 - bin.count) + bin
}
var out = "";
let un = Array(self.unicodeScalars.filter{$0.isASCII})
for i in 0...self.count - 1 {
let charCode = un[i].value
let bin = String(charCode, radix: 2)
out += "\(zeroPad(bin)) "
}
return out;
}
var decrypt: String {
let ar = self.components(separatedBy: " ")
var out = "";
for i in 0...ar.count - 2 {
let int = Int(ar[i], radix: 2)
let unScal = Unicode.Scalar(int!)
out += String(Character(unScal!))
}
return out
}
}