This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CryptoFractions { | |
Ciphertext<DCRTPoly> encryptedNumerators; | |
Ciphertext<DCRTPoly> encryptedDenominators; | |
vector<int64_t> numerators; | |
vector<int64_t> denominators; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CryptoFractions encrypt_audio(vector<float> signal, int startIndex, int sampleSize, const char *keysFilePath, const long precision) { | |
vector<int64_t> intSignal; | |
CryptoFractions encryptedSignal; | |
int numerator; | |
int endIndex = startIndex + sampleSize; | |
for (int i = startIndex; i < endIndex; i += 1) { | |
numerator = int(signal[i] * precision); | |
encryptedSignal.numerators.push_back(numerator); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*N is signal size (number of samples), sampleRate in kHz (num samples per ms), frameLength in ms, shiftLength in ms*/ | |
vector<vector<Ciphertext<DCRTPoly>>> real_discrete_fourier_transform(int N, int sampleRate, int frameLength, int shiftLength, CryptoContext<DCRTPoly> cc, LPPublicKey<DCRTPoly> publicKey, CryptoFractions encSignal, LPPrivateKey<DCRTPoly> sk) { | |
int boundN, boundM; | |
if (N % 2 == 0) { | |
boundM = N / 2 - 1; | |
boundN = N / 2; | |
} | |
else { | |
boundM = (N - 1) / 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*N is signal size (number of samples), sampleRate in kHz (num samples per ms), frameLength in ms, shiftLength in ms*/ | |
vector<vector<Ciphertext<DCRTPoly>>> real_discrete_fourier_transform(int N, int sampleRate, int frameLength, int shiftLength, CryptoContext<DCRTPoly> cc, LPPublicKey<DCRTPoly> publicKey, CryptoFractions encSignal, LPPrivateKey<DCRTPoly> sk) { | |
int boundN, boundM; | |
if (N % 2 == 0) { | |
boundM = N / 2 - 1; | |
boundN = N / 2; | |
} | |
else { | |
boundM = (N - 1) / 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Plaintext calculate_sine_array(int m, int N, int start, int stop, CryptoContext<DCRTPoly> cc) { | |
vector<int64_t> *sines = new vector<int64_t>(); | |
for (int k = 0; k != N; k++) { | |
if (k < start || k >= stop) { | |
sines->push_back(0); | |
continue; | |
} | |
int sinVal = int(sin(((2 * pi * k * m) / N)) * 100); //FOR MORE ACCURATE RESULTS, INCREASE MULTIPLE OF 10 | |
sines->push_back(sinVal); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Plaintext calculate_cosine_array(int n, int N, int start, int stop, CryptoContext<DCRTPoly> cc) { | |
vector<int64_t> *cosines = new vector<int64_t>(); | |
for (int k = 0; k != N; k++) { | |
if (k < start || k >= stop) { | |
cosines->push_back(0); | |
continue; | |
} | |
int cosVal = int(cos(((2 * pi * k * n) / N)) * 100); //FOR MORE ACCURATE RESULTS, INCREASE MULTIPLE OF 10 | |
cosines->push_back(cosVal); | |
} |