Letter by Letter Cipher

This code allows us to input a text and encode or decode it with a cipher based on permuting the 26 letters

alphabet =Characters["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
alphabet[[2]]
?String
?Permutations
?RandomSample
qq = RandomSample[alphabet,26]

(* Last argument: 1 to encode, anything else to decode *)
letterbylettercrypt[data_,permutation_] := Module[{},
Print["The code permutation is: ", permutation];
tempdata = Characters[data];
codepermutation = Characters[permutation];

For[k = 1, k≤ 26, k++,decrypt2[k] = 0];
For[k = 1, k ≤ 26, k++,
{
x = ToCharacterCode[codepermutation[[k]]];
c = x[[1]]-64;
decrypt2[c] = FromCharacterCode[64+k];
}];
printdecrypt2 = {};
For[k=1, k≤26, k++, printdecrypt2 = AppendTo[printdecrypt2, decrypt2[k]]];
Print["The decrypt key is: ",StringJoin[printdecrypt2]];

templetterbyletter= {};
For[k = 1, k ≤ Length[tempdata], k++,
{
x = ToCharacterCode[tempdata[[k]]] - 64;
y = codepermutation[[x]]; 
templetterbyletter = AppendTo[templetterbyletter, y  ];
}];
(*Print[StringJoin[tempvigeniereword]];*)
Print[StringJoin[templetterbyletter]];
];

letterbylettercrypt["THEREISNOPOSSIBILITYOFTHINKINGOFANYTHINGATALLINTHEWORLD","QWERTYUIOPASDFGHJKLZXCVBNM"]

letterbylettercrypt["THEREISNOPOSSIBILITYOFTHINKINGOFANYTHINGATALLINTHEWORLD",StringJoin[RandomSample[alphabet]]]

letterbylettercrypt["UHYWYAMVTLTMMAGAEAUZTJUHAVXAVPTJRVZUHAVPRUREEAVUHYDTWEI","IVQWLCBHDFMPSXUGJAZOTNRKEY"]

letterbylettercrypt["HELLOCRYPTOCLASSIPRAYTHATYOUALLWILLNOTACTSADUPONFINDINGHOWHARDIWORKEDTOAVOIDUSINGESINTHISTEXTITWASACONSCIOUSTHOUGHTTOAVOIDESNOWCOULDHITBRISTOLANDSTOPMYFLIGHTTHOUGHIWANTTOLANDINALBANYONSUNDAYSOICANSITINMYBUILDINGONCAMPUSSOICANTALKTOYOUONMONDAYIFYOUWISHTENBONUSPOINTSIFYOUEMAILGOPATRIOTS",StringJoin[RandomSample[alphabet]]]

letterbylettercrypt["PBLLZKWYDRZKLSGGADWSYRPSRYZJSLLCALLEZRSKRGSIJDZEXAEIAEVPZCPSWIACZWMBIRZSHZAIJGAEVBGAERPAGRBORARCSGSKZEGKAZJGRPZJVPRRZSHZAIBGEZCKZJLIPARQWAGRZLSEIGRZDNYXLAVPRRPZJVPACSERRZLSEIAESLQSEYZEGJEISYGZAKSEGARAENYQJALIAEVZEKSNDJGGZAKSERSLMRZYZJZENZEISYAXYZJCAGPRBEQZEJGDZAERGAXYZJBNSALVZDSRWAZRG", "IEWPNZSVDUCLKMXHBTAQJGRFYO"]

letterbylettercrypt["HELLOCRYPTOCLASSTENBONUSPOINTSIFYOUCANALSOTELLMEWHERETHISTEXTCOMESFROMHEREITISHISNAMEWASGAALDORNICKANDHEWASJUSTACOUNTRYBOYWHOHADNEVERSEENTRANTORBEFORETHATISNOTINREALLIFEHEHADSEENITMANYTIMESONTHEHYPERVIDEOANDOCCASIONALLYINTREMENDOUSTHREEDIMENSIONALNEWSCASTSCOVERINGANIMPERIALCORONATIONORTHEOPENINGOFAGALACTICCOUNCILEVENTHOUGHHEHADLIVEDALLHISLIFEONTHEWORLDOFSYNNAXWHICHCIRCLEDASTARATTHEEDGESOFTHEBLUEDRIFTHEWASNOTCUTOFFFROMCIVILIZATIONYOUSEEATTHATTIMENOPLACEINTHEGALAXYWASTHEREWERENEARLYTWENTYFIVEMILLIONINHABITEDPLANETSINTHEGALAXYTHENANDNOTONEBUTOWEDALLEGIANCETOTHEEMPIREWHOSESEATWASONTRANTORITWASTHELASTHALFCENTURYINWHICHTHATCOULDBESAIDTOGAALTHISTRIPWASTHEUNDOUBTEDCLIMAXOFHISYOUNGSCHOLARLYLIFEHEHADBEENINSPACEBEFORESOTHATTHETRIPASAVOYAGEANDNOTHINGMOREMEANTLITTLETOHIMTOBESUREHEHADTRAVELEDPREVIOUSLYONLYASFARASSYNNAX'SONLYSATELLITEINORDERTOGETTHEDATAONTHEMECHANICSOFMETEORDRIFTAGEWHICHHENEEDEDFORHISDISSERTATIONBUTSPACETRAVELWASALLONEWHETHERONETRAVELLEDHALFAMILLIONMILESORASMANYLIGHTYEARS",StringJoin[RandomSample[alphabet]]]

letterbylettercrypt["YDHHAFVNSIAFHJTTIDQKAQRTSAEQITEWNARFJQJHTAIDHHGDZYDVDIYETIDBIFAGDTWVAGYDVDEIETYETQJGDZJTOJJHPAVQEFUJQPYDZJTCRTIJFARQIVNKANZYAYJPQDLDVTDDQIVJQIAVKDWAVDIYJIETQAIEQVDJHHEWDYDYJPTDDQEIGJQNIEGDTAQIYDYNSDVLEPDAJQPAFFJTEAQJHHNEQIVDGDQPARTIYVDDPEGDQTEAQJHQDZTFJTITFALDVEQOJQEGSDVEJHFAVAQJIEAQAVIYDASDQEQOAWJOJHJFIEFFARQFEHDLDQIYAROYYDYJPHELDPJHHYETHEWDAQIYDZAVHPAWTNQQJBZYEFYFEVFHDPJTIJVJIIYDDPODTAWIYDKHRDPVEWIYDZJTQAIFRIAWWWVAGFELEHEMJIEAQNARTDDJIIYJIIEGDQASHJFDEQIYDOJHJBNZJTIYDVDZDVDQDJVHNIZDQINWELDGEHHEAQEQYJKEIDPSHJQDITEQIYDOJHJBNIYDQJQPQAIAQDKRIAZDPJHHDOEJQFDIAIYDDGSEVDZYATDTDJIZJTAQIVJQIAVEIZJTIYDHJTIYJHWFDQIRVNEQZYEFYIYJIFARHPKDTJEPIAOJJHIYETIVESZJTIYDRQPARKIDPFHEGJBAWYETNARQOTFYAHJVHNHEWDYDYJPKDDQEQTSJFDKDWAVDTAIYJIIYDIVESJTJLANJODJQPQAIYEQOGAVDGDJQIHEIIHDIAYEGIAKDTRVDYDYJPIVJLDHDPSVDLEARTHNAQHNJTWJVJTTNQQJBKTAQHNTJIDHHEIDEQAVPDVIAODIIYDPJIJAQIYDGDFYJQEFTAWGDIDAVPVEWIJODZYEFYYDQDDPDPWAVYETPETTDVIJIEAQKRITSJFDIVJLDHZJTJHHAQDZYDIYDVAQDIVJLDHHDPYJHWJGEHHEAQGEHDTAVJTGJQNHEOYINDJVT","OXJEICMLTABVZYGDNUPSKRFQHW"]