Convert the ASCII string “The quick brown fox jumps over t” into a 32-byte key

key = ToCharacterCode["The quick brown fox jumps over t"];BaseForm[key,16]

nonce=IntegerDigits[Floor[Pi 2^44],16];BaseForm[nonce,16]

A = {{16^^61707865,16^^3320646e,16^^79622d32,16^^6b206574},Table[Sum[256^(i-1) key[[4 n+i]],{i,1,4}],{n,0,3}],Table[Sum[256^(i-1) key[[4 n+i]],{i,1,4}],{n,4,7}],Join[{1},Table[Sum[256^(i-1) nonce[[4 n+i]],{i,1,4}],{n,0,2}]]};TableForm[IntegerString[A,16,8]]

ShiftLeft[a_,n_] :=FromDigits[RotateLeft[PadLeft[IntegerDigits[a,2],32],n],2]

QuarterRound[A_,x_,y_,z_,w_,n_] :=Block[{B = Flatten[A],X=x+1,Y=y+1,Z=z+1,W=w+1},Block[{a=B[[X]],b=B[[Y]],c=B[[Z]],d=B[[W]]},
If[n==0,Return[ArrayReshape[B,{4,4}]]];
a=Mod[a+b,2^32];If[n==1,B[[X]]=a;B[[Y]]=b;B[[Z]]=c;B[[W]]=d;Return[ArrayReshape[B,{4,4}]]];
d=BitXor[d,a];If[n==2,B[[X]]=a;B[[Y]]=b;B[[Z]]=c;B[[W]]=d;Return[ArrayReshape[B,{4,4}]]];
d=ShiftLeft[d,16];If[n==3,B[[X]]=a;B[[Y]]=b;B[[Z]]=c;B[[W]]=d;Return[ArrayReshape[B,{4,4}]]];
c=Mod[c+d,2^32];If[n==4,B[[X]]=a;B[[Y]]=b;B[[Z]]=c;B[[W]]=d;Return[ArrayReshape[B,{4,4}]]];
b=BitXor[b,c];If[n==5,B[[x+1]]=a;B[[y+1]]=b;B[[z+1]]=c;B[[w+1]]=d;Return[ArrayReshape[B,{4,4}]]];
b=ShiftLeft[b,12];If[n==6,B[[X]]=a;B[[Y]]=b;B[[Z]]=c;B[[W]]=d;Return[ArrayReshape[B,{4,4}]]];
a=Mod[a+b,2^32];If[n==7,B[[X]]=a;B[[Y]]=b;B[[Z]]=c;B[[W]]=d;Return[ArrayReshape[B,{4,4}]]];
d=BitXor[d,a];If[n==8,B[[X]]=a;B[[Y]]=b;B[[Z]]=c;B[[W]]=d;Return[ArrayReshape[B,{4,4}]]];
d=ShiftLeft[d,8];If[n==9,B[[X]]=a;B[[Y]]=b;B[[Z]]=c;B[[W]]=d;Return[ArrayReshape[B,{4,4}]]];
c=Mod[c+d,2^32];If[n==10,B[[X]]=a;B[[Y]]=b;B[[Z]]=c;B[[W]]=d;Return[ArrayReshape[B,{4,4}]]];
b=BitXor[b,c];If[n==11,B[[X]]=a;B[[Y]]=b;B[[Z]]=c;B[[W]]=d;Return[ArrayReshape[B,{4,4}]]];
b=ShiftLeft[b,7];If[n==12,B[[X]]=a;B[[Y]]=b;B[[Z]]=c;B[[W]]=d;Return[ArrayReshape[B,{4,4}]]];
{a,b,c,d}]]

Quarter round on two successive blocks (with block counter incremented)

Manipulate[{TableForm[IntegerString[QuarterRound[A,0,4,8,12,n],16,8]],TableForm[IntegerString[QuarterRound[A+{{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,0,0,0}},0,4,8,12,n],16,8]]},{n,0,12,1}]

ChaCha20Round[A_,n_]:=Block[{B=A},
If[n<12,Return[QuarterRound[B,0,4,8,12,Mod[n,12]]],B=QuarterRound[B,0,4,8,12,12]];
If[n<24,Return[QuarterRound[B,1,5,9,13,Mod[n,12]]],B=QuarterRound[B,1,5,9,13,12]];
If[n<36,Return[QuarterRound[B,2,6,10,14,Mod[n,12]]],B=QuarterRound[B,2,6,10,14,12]];
If[n<48,Return[QuarterRound[B,3,7,11,15,Mod[n,12]]],B=QuarterRound[B,3,7,11,15,12]];
If[n<60,Return[QuarterRound[B,0,5,10,15,Mod[n,12]]],B=QuarterRound[B,0,5,10,15,12]];
If[n<72,Return[QuarterRound[B,1,6,11,12,Mod[n,12]]],B=QuarterRound[B,1,6,11,12,12]];
If[n<84,Return[QuarterRound[B,2,7,8,13,Mod[n,12]]],B=QuarterRound[B,2,7,8,13,12]];
If[n<96,Return[QuarterRound[B,3,4,9,14,Mod[n,12]]],B=QuarterRound[B,3,4,9,14,12]];
B]

Manipulate[{TableForm[IntegerString[ChaCha20Round[A,n],16,8]],TableForm[IntegerString[ChaCha20Round[A+{{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,0,0,0}},n],16,8]]},{n,0,96,1}]

ChaCha20[A_,n_]:=Block[{B=A},
If[n<96 1,Return[ChaCha20Round[B,Mod[n,96]]],B=ChaCha20Round[B,96]];
If[n<96 2,Return[ChaCha20Round[B,Mod[n,96]]],B=ChaCha20Round[B,96]];
If[n<96 3,Return[ChaCha20Round[B,Mod[n,96]]],B=ChaCha20Round[B,96]];
If[n<96 4,Return[ChaCha20Round[B,Mod[n,96]]],B=ChaCha20Round[B,96]];
If[n<96 5,Return[ChaCha20Round[B,Mod[n,96]]],B=ChaCha20Round[B,96]];
If[n<96 6,Return[ChaCha20Round[B,Mod[n,96]]],B=ChaCha20Round[B,96]];If[n<96 7,Return[ChaCha20Round[B,Mod[n,96]]],B=ChaCha20Round[B,96]];If[n<96 8,Return[ChaCha20Round[B,Mod[n,96]]],B=ChaCha20Round[B,96]];
If[n<96 9,Return[ChaCha20Round[B,Mod[n,96]]],B=ChaCha20Round[B,96]];If[n<96 10,Return[ChaCha20Round[B,Mod[n,96]]],B=ChaCha20Round[B,96]];
If[n==96 10,B,Mod[A+B,2^32]]]

Full cipher on two successive blocks (with block counter incremented)

Manipulate[{TableForm[IntegerString[ChaCha20[A,n],16,8]],TableForm[IntegerString[ChaCha20[A+{{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,0,0,0}},n],16,8]]},{n,0,961,1}]

Test state for full cipher from RFC 7539

Test={{16^^61707865,16^^3320646e,16^^79622d32,16^^6b206574},{16^^03020100,16^^07060504,16^^0b0a0908,16^^0f0e0d0c},{16^^13121110,16^^17161514,16^^1b1a1918,16^^1f1e1d1c},{16^^00000001,16^^09000000,16^^4a000000,16^^00000000}}

Manipulate[TableForm[IntegerString[ChaCha20[Test,n],16,8]],{n,0,961,1}]

Test state for single quarter round from RFC 7539

TestRound={{16^^879531e0,16^^c5ecf37d,16^^516461b1,16^^c9a62f8a},{16^^44c20ef3,16^^3390af7f,16^^d9fc690b,16^^2a5f714c},{16^^53372767,16^^b00a5631,16^^974c541a,16^^359e9963},{16^^5c971061,16^^3d631689,16^^2098d9d6,16^^91dbd320}}

Manipulate[TableForm[IntegerString[QuarterRound[TestRound,2,7,8,13,n],16,8]],{n,0,12,1}]

Test state for single vector quarter round from RFC 7539

TestQR = {{0,0,16^^11111111,0},{0,0,0,16^^01020304},{16^^9b8d6f43,0,0,0},{0,16^^01234567,0,0}}

Manipulate[TableForm[IntegerString[QuarterRound[TestQR,2,7,8,13,n],16,8]],{n,0,12,1}]