-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipher.cl
More file actions
29 lines (28 loc) · 824 Bytes
/
cipher.cl
File metadata and controls
29 lines (28 loc) · 824 Bytes
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
/* cipher.cl
* by Kurt D kurtd5105@gmail.com
* Description: Contains an encryption and decryption algorithm function for the Vigenere cipher.
*/
__kernel void encrypt(__global int* plaintext, __global int* key, __global int* ciphertext){
// Get the ID to work on its own part of the ciphertext
uint i = get_global_id(0);
// Don't modify characters under 32
if(plaintext[i] > 31){
ciphertext[i] = plaintext[i] + key[i] - 32;
if(ciphertext[i] > 126){
ciphertext[i] -= 95;
}
} else {
ciphertext[i] = plaintext[i];
}
}
__kernel void decrypt(__global int* plaintext, __global int* key, __global int* ciphertext){
uint i = get_global_id(0);
if(plaintext[i] > 31){
ciphertext[i] = plaintext[i] - key[i] + 32;
if(ciphertext[i] < 32){
ciphertext[i] += 95;
}
} else {
ciphertext[i] = plaintext[i];
}
}