Newer
Older
#include <hls_stream.h>
#include <ap_axi_sdata.h>
) {
#pragma HLS INTERFACE ap_ctrl_none port=return
#pragma HLS INTERFACE s_axilite port=position1
#pragma HLS INTERFACE s_axilite port=position2
#pragma HLS INTERFACE axis port=din
#pragma HLS INTERFACE axis port=dout
switch(selector)
{
case 0:
if (count_streams == 0){
charIn=convert(ascii);
if((count_streams >= 3 * (position1 - 1)) && (count_streams < 3 * (position2) - 1)){
addNum=0;
if(charIn!=0){
addNum=charIn%10;
charIn=(int)charIn/10;
}
if(pkt.data % 2 == 0 && addNum == 1){
pkt.data += 1;
}else if(pkt.data % 2 != 0 && addNum == 0){
pkt.data -= 1;
}
if((count_streams >= 3 * (position1 - 1)) && (count_streams < 3 * (position2)-1)){
decrypt(pkt.data);
}
break;
default:
break;
}
long long convert(int n) {
long long bin = 0;
int rem, i = 1, step = 1;
while (n != 0) {
rem = n % 2;
n /= 2;
bin += rem * i;
i *= 10;
}
return bin;
}
void decrypt(int data) {
int bit;
if(data % 2 == 0){
bit = 0;
}else if(data % 2 != 0){
bit=1;
}
final_char= final_char*10+bit;