Tiny encryption Algorithm for 16 bit voice samples

As my college project I am trying to implement a very basic voice scrambler/encryption using arduino. :-X

Block diagram:
Mic—> Audio codec—> Arduino No 1—> Audio codec----> output scrambled/encrypted voice
This voice is transmitted over motorolla radio or any other form of audio transmission device

At decoder side
scrambled voice input —> Voice Codec----> Arduino No 2 → voice cable----> original voice

The audio codec takes in voice input and gives 16 Bit samples at 8kbps to arduino no 1.
the arduino no 1 is where I am doing programming to scramble/encrypt this sample of 16 bit and send to output voice codec which converts it back to voice and transmits it over aux cable or radio to the decoder side where decoding takes place.

Things I have tried so far for scrambling/encryption. :confused:

  1. Bitwise exor the input 16 bit sample with 16 bit key --------- result : Voice is still not scrambled/encrypted.

  2. Bitwise exor with random(65534L) ---- perfect encryption… but not able to decrypt at receiver.

  3. Bitwise exor with 30 keys, one after the other… result: voice is still not scrambled/encrypted.

  4. Caeser cipher (basically a shift cipher)… result: voice still not properly muffled.

  5. mixing with sine wave tone… result : voice not clearly heard at output… but not able to remove sine wave at decoder side…

Some code samples I have been trying : :roll_eyes:

//simple exor with key=23452
// left_in is the left channel voice input which is 16 bit sample 
  left_out=left_in; // send ex ORed output
// exor with sine wave
left_out=left_in^temp2; // temp2 is a sine wave function
//trying to invert the input voice sample by subtracting with max value of 65534

// digit wise caeser shift cipher. shift input sample based on key
// eg : if key =21212 and sample =32132… then output is 51344.
//based on key… shift the
int x,y,z,u,z;
int s=left_in;
left_out = s;

Not good output of this also. :sob:

If i use a self made random generator… it gives me good encryption but At decoder i need to sync the decryption process to get output , else I just get noise.
Here probably I need a DTMF code sent by the transmitter which tells the receiver side to start its decryption process at that instant… basically sync vector.

please help me in this code.
My restriction is that the audio codec gives me 16 bit sample… and I must change it and send it to output before next sample value comes in… (sampling rate is 8khz)

Can someone guide me how to play with time domain… shuffling…
or in freqn domain

I know very basic level of coding as you can see from my code above…

I feel if I can implement a audio sync vector… like a DTMF tone sent by the transmission side before starting encryption/scrambling… the receiver can get in sync by detection it and the code as per point 2 above may work…

because if i try encoding and decoding on same audrino… it gives back voice

Left_in=left_in^random(65534L)    // encryption
Left_in=left_in^^random(65534L)    //decryption
left_out=left_in  // output gives original voice

But if i do this encryption and decryption on seperate audrino… i just get noice…
And my guess is that its cause of not being in sync…
bacically the decoder needs to exor an input sample with the same value that was used to encrypt that particular sample at the input.

Someone told me to try TEA algorithm for encryption :neutral_face:
Link to TEA code page

Im getting the following error using TEA code :roll_eyes:

invalid conversion from uint32_t to uint32_t*

Could you guide a little :zipper_mouth_face:

#define SAMPLE_RATE 8 // 8Khz

// include necessary libraries
#include <Wire.h>
#include <SPI.h>
#include <AudioCodec.h>
#include <stdint.h>

// create data variables for audio transfer
int left_in = 0x0000;
int left_out = 0x0000;
int right_in = 0x0000;
int right_out = 0x0000;

void setup() {
  AudioCodec_init(); // setup codec registers
  // call this last if setting up other parts

void loop() {
  while (1); // reduces clock jitter

//encryption function
void encrypt (uint32_t* v, uint32_t* k) 
    uint32_t v0=v[0], v1=v[1], sum=0, i;           /* set up */
    uint32_t delta=0x9e3779b9;                     /* a key schedule constant */
    uint32_t k0=k[0], k1=k[1], k2=k[2], k3=k[3];   /* cache key */
    for (i=0; i < 32; i++) {                       /* basic cycle start */
        sum += delta;
        v0 += ((v1<<4) + k0) ^ (v1 + sum) ^ ((v1>>5) + k1);
        v1 += ((v0<<4) + k2) ^ (v0 + sum) ^ ((v0>>5) + k3);
    }                                              /* end cycle */
    v[0]=v0; v[1]=v1;

// timer1 interrupt routine - all data processed here

  // &'s are necessary on data_in variables
  AudioCodec_data(&left_in, &right_in, left_out, right_out);
uint32_t input_sample = left_in;
uint32_t key=25509;

//call encryption function
encrypt(input_sample,key);                                               // getting error here

//send encrypted output

// dont forget to return from interrupt

Could someone give a simple code for voice scrambling so that I can get started..... Something as simple as like voice inversion

i know it is not encryption secure.... but atleast its first level of muffling voice

Do not double post.

invalid conversion from uint32_t to uint32_t*

Seems like a simple well-placed & would fix that.

deepank_singh: Could someone give a simple code for voice scrambling so that I can get started..... Something as simple as like voice inversion

Voice inversion is not something you do with an Arduino. You either do it in analog hardware or in a Digital Signal Processor. http://en.wikipedia.org/wiki/Voice_inversion

:roll_eyes: can someone give a simple code for trying basic voice encryption. (Simple exor with a key does not work for voice samples.)


But if we exor every sample with a different value using a key generator like random(key), it works. could someone guide me how to make a sync vector to syncronize the random(65534L) function on two different arduino. basically i need to send a tone like a DTMF tone after which the decoder side should start the decryption using the random(65534L) function.

It seems to me, once you have digitised the original voice signal to 16 bit numbers, you can encrypt that using the same method you would use for encrypting anything else, like 16 bit text

And, it seems to me, as your college project, you should do your own research or figure it out for yourself.

michinyon: It seems to me, once you have digitised the original voice signal to 16 bit numbers, you can encrypt that using the same method you would use for encrypting anything else, like 16 bit text

actually, i can use any encryption. and that i already have done. but the issue is that at receiver the decryption process has to be in sync with transmitter side. which i am not able to do. in short... the encoder encrypts sample 1 with key 1 sample 2 with key 2 sample 3 with key 3 sample 4 with key 4 and so on....

where key 1, key 2, key 3 .... are generated using a key generator using KEY as master key... simething like key = (KEY *KEY)%65534 so at decryptor i need to sync it... so that key 1 is used to decrypt sample 1 and key 2 for sample 2..... its all realtime transmission... so i need something like a dtmf sync vector which is detected at receiver and after which it starts decryption... help plz

jremington: Do not double post.

My fault.

I suggested programming was the better place for his question