Encrypting Algorithm dont give all the output

I’m currently trying to write an encrypting algorithm as:
TXT the sequence of characters to be encrypted
ENC the output sequence (at the beginning, ENC is empty)

i) I take C, the first character of TXT, and add it to the end of ENC.

ii) let X be the ASCII code of C modulo 8 (e.g. for the letter ‘b’, its ASCII code is 98, so X = 2)

iii) I take the first X characters of TXT and move them to the end of TXT (if there are at least X characters left in TXT)

iv) repeat until TXT is empty

at the end, ENC will contain the encrypted message.

envoyer, envoyer_recevoir are just some functions to communicate with the server. The message i’m trying to crypte is:

Chere Alice,

Nous devons etre plus prudents, il faut anticiper avant que nous ne soyons
reperes. J’ai termine dans l’urgence mon nouveau schema de chiffrement que j’ai
appele ‘crypteMove’.
Durant l’encryption, nous allons modifier l’ordre des lettres du texte selon
des regles bien etablies. Voici le principe :

soit TXT la sequence des caracteres a encrypter
soit ENC la sequence de sortie
(au debut, ENC est vide)
j’effectue ensuite la manipulation suivante:
i) je prends C le premier caractere de TXT et le rajoute a la fin de ENC
ii) soit X le code ASCII de C modulo 8 (par exemple pour la lettre ‘b’, son
code ASCII est 98 donc X = 2)
iii) je prends les X premiers caracteres de TXT et les deplace a la fin de TXT
(s’il reste au moins X caracteres dans TXT)
iv) je recommence jusqu’a ce que TXT soit vide
a la fin, ENC contiendra le message encrypte.

Je te donne un exemple sur le message suivant :
“Petit message court.”
Devient :
“Pee ct mosusriae.ttg”

Je sais que tu es l’une des rares personnes a pouvoir mettre en oeuvre une
technique complexe comme celle-ci, cela devrait mieux nous proteger que le code
de cesar que nous utilisions jusqu’a present. Cependant, pour me montrer que tu
as bien compris ma methode, il faut dans un premier temps que tu me renvoies ce
message complet crypte comme je viens de te l’expliquer.

Bien a toi,
Bob.

PS: Pour t’aider, voici la trace d’execution sur “Petit message court.”

TXT:Petit message court.
ENC: <vide>
C = P

TXT:etit message court.
ENC:P
C = e

TXT:essage court.tit m
ENC:Pe
C = e

TXT: court.tit mssage
ENC:Pee
C =

TXT:court.tit mssage
ENC:Pee
C = c

TXT:t.tit mssageour
ENC:Pee c
C = t

TXT: mssageour.tit
ENC:Pee ct
C =

TXT:mssageour.tit
ENC:Pee ct
C = m

TXT:our.titssage
ENC:Pee ct m
C = o

TXT:sageur.tits
ENC:Pee ct mo
C = s

TXT:ur.titsage
ENC:Pee ct mos
C = u

TXT:sager.tit
ENC:Pee ct mosu
C = s

TXT:r.titage
ENC:Pee ct mosus
C = r

TXT:itage.t
ENC:Pee ct mosusr
C = i

TXT:age.tt
ENC:Pee ct mosusri
C = a

TXT:e.ttg
ENC:Pee ct mosusria
C = e

TXT:.ttg
ENC:Pee ct mosusriae
C = .

TXT:ttg
ENC:Pee ct mosusriae.
C = t

TXT:tg
ENC:Pee ct mosusriae.t
C = t

TXT:g
ENC:Pee ct mosusriae.tt
C = g

TXT: <vide>
ENC:Pee ct mosusriae.ttg

As output i get:

Ceeuo plrei ftenn sneJitn leoa smcf qe
pertertno almerelet snrlinisoprc : s Taseeat aet s E seei
(a d, ed jf eeaiunnedlecceXTljtlnCo c ACdm 8 (pa ee lt’
c ACe dX = edsprircceTt dc lnT (s rt mX ccesTem jq’es valncin meytJtneelseat “te cte : “eo.Js qesusr peeoeev
cqelceec di mnouc
crusiiinue Cnpoou
bni mhofnrireumves clrtm ve’ein,.Podvat dcoPee ctTee ctCv =XTts ctCCe:s ct mPee:o m
Ce
XTrtsePe=XTi moPe =XTsoEe =XTaei
CeCm:risePemoaetCeo
Ttgem=XTe
CeosXTiaePemCrTtt:eo=XT.:eo =XTtCeoCe:tCeo
=XT
Ceo.
XTEeo.tTNco. g<>emiehecNnunuc aa qen
pr.mncnudfualye
a lytnsii l dtdt
see.lieXTqncecetaqnob Evee lpl saejrseete eefNteIeumut’otn jrs X ere XTeeid
‘uaaen jecuq Tiie f ola e.dupl eg:Pesoincsie
asunasnumn unpem-laiu prgeeeu jqaprnat mr q ti cr m i at ue q tromope jetxpl. touiroaetutae
TtaeEd P
:imoP

XTei
C =Ttse
=osE
c:tg:ct mri
c
:srte =TtEcC
XTri
c
=:.E cs uariEcs =rtCcs =:ges
i
aeCcsiC
eN ma =TEcsie
t: csietgcsie
X:E tse=:iePesat Ai
svsdlnuers ea’ neiejieoe,ldde eds t Vip
i lereproc s useeunv peprrrr Truid s lI Clplalbs d sopeerdlaa f ieisrd) rmacXT
a,nec
enuasnmr
e trt i t’rno oeocceetq ldqnotdrmumd dpeses
aecode
aiB
t iile stsr
PtsrN
Tsu:
suNTrisN
ci m:CTsrN
:gPemt c
XoN

ste suee
tCT
:t

ieP cuT
PesaT
Pes
X.es .NsC
tPes
=:eit
XTEtrgdtutpr o ei dne hrn’ui orr txeebiie e arnCuet-naiu n ae a aa eXoo eo9c) nate aeso TeedErepee se
tet m”u dsapveec o avs esose,nssenei cgcis l
o’cuim”im
<
e
=rt
ctPeu
e.E
auts.
u
eTst
rsC ot m:gsTNCgm:gr
gmTPea =C m

ea

vcsr
e pt aitysae maea c’nf ug ndr-eu)’am
Ci d ESdpo e 2la el l r a
n otsr o m is.e
ersrte mlr oe t’ ueatst em mee r,’ s.u>rNt
TaNt

st
o
t: =NXiaNT:ut oEr:Er
EuNr
g T tCP m TCo sev ‘ueMcsolbltc
lt if t m
dr r ,I8
ms Tnu-enei auPu louulxudusereupus yeuPS rirgotE.tCt
sCeCETCg Ttg
Na
mN.iT t:t
Ngd uoiseemvueecc yNNiooeI eease iN
xmgt ern ee l.e, mpeirbe”X:gaeog
etgstP m
see.t
:t:umusC:teuuh t.neesd
uae os p Xest sru setieese apen q
c oeeCECe
Ng
CP
.C
t c
at:rT
.,o ‘o esrCttxrnt ueDeeieautmee:CT
a:gCPt:Et u tt CraCNsoppD ‘octe scCnaettse e
ne::t.au

s sEu, rgo i e i eXovirm pneug.uCN u
r
rscpsau:S d”g ot s.aC: .Xt u ao- as hx,lB.u .
lrov nETEr’ga igP tni
oNrteutsxatt rTsXtte:v

Current ENC Len 2247
Current Txt Len 0

And server says that i make a mistake on 2245th character and “vs tteaPv:” is missing. I used address sanitizer and also add some checkpoints but i couldn’t get anything.

 #include "client.h"
 #include <ctype.h>
 #include <stdbool.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>


 char TXT[MAXREP];//MAXREP is given by server and =100000
 char ENC[MAXREP];
 char C;
 int lenENC_courant=0;

 void delete(char txt[],int x){
     int len= strlen(txt);
     if (x >= len) {
         txt[0] = '';
         return;
     }
     for (int i = 0; i < len - x; i++) {
         txt[i] = txt[i + x];
     }
     if(len -x>0){
         txt[len - x] = '';
     }
 }

 void add(char txt[], int x, int lentxt){
     if (lentxt + x >= MAXREP) {
         printf("Error: Buffer overflow risk, cannot add charactersn");
         return;
     }
     for (int i = 0; i < x && i<lentxt; i++) {
         if(lentxt +i<MAXREP){
         txt[lentxt + i] = txt[i];
         }
     }
     txt[lentxt + x] = '';
 }
 
 void encrypte(char txt[]){
     if(strlen(txt)==0){
         return;
     }

     int x = (int) txt[0] % 8;
     C= txt[0];

     if(lenENC_courant <=MAXREP-1){
         ENC[lenENC_courant++]=C;
         ENC[lenENC_courant] = '';
     }
     if (lenENC_courant >= MAXREP - 1) {
         printf("Error: Buffer overflow risk in 'ENC' arrayn");
         ENC[MAXREP - 1] = '';  
         return;
     }
    
     if(x==0){
         delete(txt,1);
       
     }
     else{
         delete(txt,1);
         int lentxt = strlen(txt);
         if(lentxt+x<= MAXREP){
             add(txt,x,lentxt);
         } 
         delete(txt,x);
     }
 }


 int main() {
     char reponse[MAXREP] = "Petit message court."; 
     connexion("**********");
     mode_debug(true);
     envoyer("login ******* *******");
     envoyer("load crypteMove");
     envoyer_recevoir("help",reponse);
     if(reponse==NULL){
         printf("On n'a pas pu prendre le reponse");
         return -1;
     }
     envoyer("start");

    
     while(strlen(reponse)>0){
         encrypte(reponse);
     } 
     envoyer(ENC);
     printf("nCurrent ENC Len %d n",lenENC_courant);
     int len_txt = strlen(TXT);
     printf("Current Txt Len  %dn",len_txt);

     return 0;
 }

12

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật