Skip to content

Instantly share code, notes, and snippets.

/*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;
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);
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);
}
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);
}
struct CryptoFractions {
Ciphertext<DCRTPoly> encryptedNumerators;
Ciphertext<DCRTPoly> encryptedDenominators;
vector<int64_t> numerators;
vector<int64_t> denominators;
};
/*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;