You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: index.md
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,25 +10,25 @@ title: Home
10
10
});
11
11
</script>
12
12
13
-
# : Image Encryption
13
+
# Image Encryption
14
14
15
-
## : Introduction
16
-
Images like any other data format can very easily be encrypted using standard algorithms like RSA or AES but those result in a meaningless blob that cant be used anywhere. Sometimes it's worth keeping some properties to allow for file uploads to share it with others in places where images are only allowed.
15
+
## Introduction
16
+
Images like any other data format can very easily be encrypted using standard algorithms like RSA or AES but those result in a meaningless blob that cant be used anywhere. Sometimes it's worth keeping some properties to allow for file uploads to share it with others in places where images are only allowed.
17
17
18
-
## : Basic Encryption
19
-
This step is fairly easy to implement, one can easily take a block of a few pixels and encrypt them and interpret the resulting data also as pixels. This allows one to upload the encrypted image on social media or chat apps that restrict file uploads to images. However some apps do additional processing like scaling the image and the new algorithm for encryption doesn't work anymore. When the image is scaled the algorithm usually involves some interpolation so the resulting pixels are different from the starting pixels and the decryption breaks
18
+
## Basic Encryption
19
+
This step is fairly easy to implement, one can easily take a block of a few pixels and encrypt them and interpret the resulting data also as pixels. This allows one to upload the encrypted image on social media or chat apps that restrict file uploads to images. However some apps do additional processing like scaling the image and the new algorithm for encryption doesn't work anymore. When the image is scaled the algorithm usually involves some interpolation so the resulting pixels are different from the starting pixels and the decryption breaks
20
20
//TODO: add image for this
21
21
22
-
The knee-jerk reaction to trying to work with encrypted data is [:Homomorphic Encryption](#HomomorphicEncryption). However there are a [:few specific issues](#IssuesWithHomomorphicEncryption) that make this not optimal.
22
+
The knee-jerk reaction to trying to work with encrypted data is [:Homomorphic Encryption](#HomomorphicEncryption). However there are a [:few specific issues](#IssuesWithHomomorphicEncryption) that make this not optimal.
23
23
24
24
## :x Homomorphic Encryption
25
-
Homomorphic Encryption is a scheme where operations can be perfomed on the encrypted data which corresponds to an operation on the initial data. This can be written as encrypt(f(a)) = g(encrypt(a)) or in the binary operation case encrypt(f(a,b)) = g(encrypt(a),encrypt(b))
25
+
Homomorphic Encryption is a scheme where operations can be perfomed on the encrypted data which corresponds to an operation on the initial data. This can be written as encrypt(f(a)) = g(encrypt(a)) or in the binary operation case encrypt(f(a,b)) = g(encrypt(a),encrypt(b))
26
26
27
27
## :x Issues with Homomorphic Encryption
28
-
In Homomorphic Encryption there is no control over the algorithm used on the encrypted image, this is both in terms of the actual logic of the algorithm and also that it wont involve the required operators that map from the unencrypted domain to the encrypted domain. Secondly the calculations are usually performed in floating point and converted to integers at the end which doesn't play well with most Homomorphic Encryption schemes
28
+
In Homomorphic Encryption there is no control over the algorithm used on the encrypted image, this is both in terms of the actual logic of the algorithm and also that it wont involve the required operators that map from the unencrypted domain to the encrypted domain. Secondly the calculations are usually performed in floating point and converted to integers at the end which doesn't play well with most Homomorphic Encryption schemes
29
29
30
-
## :xThe Problem
31
-
Before we move on with the potentials solutions we have to define the problem to be solved first:
30
+
## The Problem
31
+
Before we move on with the potentials solutions we have to define the problem to be solved first:
32
32
- Encryption must convert images to images.
33
33
- Images must be in a commonly used format preferably the same format as the input image. [:Why?](#whyACommonFormat)
34
34
- Encrypted image must be the same size as the initial image. [:Why?](#whySameSize)
@@ -37,23 +37,23 @@ title: Home
37
37
- Encryption may be lossy as long as the image is mostly preserved.
38
38
39
39
### :x Why a Common Format
40
-
This is so that the image can be rendered and scaled by the application
40
+
This is so that the image can be rendered and scaled by the application
41
41
42
42
### :x Why Same Size
43
-
This is so that the user need not waste extra bandwidth for downloading large images just because they are encrypted
43
+
This is so that the user need not waste extra bandwidth for downloading large images just because they are encrypted
44
44
45
45
## Frequency Domain
46
-
Now that we have specified the constraints the most obvious solution is to work with the image in the frequency domain with a [:Direct Cosine Transform](#DCT). This is because a scaling operation is [:analogous to a crop](#DCTAndScaling) of the top left part of the DCT of the corresponding size.
46
+
Now that we have specified the constraints the most obvious solution is to work with the image in the frequency domain with a [:Direct Cosine Transform](#DCT). This is because a scaling operation is [:analogous to a crop](#DCTAndScaling) of the top left part of the DCT of the corresponding size.
47
47
48
48
### :x DCT
49
-
DCT is an operation that converts an image to a same shaped matrix of frequencies with the lower frequencies being at the top left and the higher frequencies at the bottom right. The coefficients are real valued unlike a fourier transform and they represent a sum of cosines. It is an invertable operation and theoretically no data is lost however floating point errors will creep in.
49
+
DCT is an operation that converts an image to a same shaped matrix of frequencies with the lower frequencies being at the top left and the higher frequencies at the bottom right. The coefficients are real valued unlike a fourier transform and they represent a sum of cosines. It is an invertable operation and theoretically no data is lost however floating point errors will creep in.
50
50
51
51
### :x DCT and Scaling
52
-
Scaling process deletes high frequency data and leaves the low frequency data. When an image is scaled usually the high quality detail is smoothed away leading to the deletion of the high frequency data but the low frequency data which tells more about the image overall is preserved. In other words scaling is basically a resampling of the signal which would lead to the high frequency region to get cutoff.
52
+
Scaling process deletes high frequency data and leaves the low frequency data. When an image is scaled usually the high quality detail is smoothed away leading to the deletion of the high frequency data but the low frequency data which tells more about the image overall is preserved. In other words scaling is basically a resampling of the signal which would lead to the high frequency region to get cutoff.
53
53
54
54
## The Naïve Encryption
55
-
The naïve way to encrypt would be to use AES. This is by taking 2 coefficients at a time and encrypting them. [:Why?](#why2Coefficients) the resulting coefficients can be converted to an image through an inverse DCT to get the final encrypted image
56
-
This method has an issue the resulting image will have amplitudes which aren't bounded, however we need the image amplitudes to be between 0 and 255
55
+
The naïve way to encrypt would be to use AES. This is by taking 2 coefficients at a time and encrypting them. [:Why?](#why2Coefficients) the resulting coefficients can be converted to an image through an inverse DCT to get the final encrypted image
56
+
This method has an issue the resulting image will have amplitudes which aren't bounded, however we need the image amplitudes to be between 0 and 255
57
57
58
-
### Why 2 Coefficients
59
-
Each coefficent will be represented as a double precision float(float64), since AES takes 128 bits as an input two of them together can form the input and the encrypted result of 128 bits can be split back into two floats, while decrypting if any pair is split due to the cropping it has to be neglected but the rest of the image can be decrypted resulting in a slightly smaller image.
58
+
### :xWhy 2 Coefficients
59
+
Each coefficent will be represented as a double precision float(float64), since AES takes 128 bits as an input two of them together can form the input and the encrypted result of 128 bits can be split back into two floats, while decrypting if any pair is split due to the cropping it has to be neglected but the rest of the image can be decrypted resulting in a slightly smaller image.
0 commit comments