Here you go. Note that the input and output characters could be (almost) arbitrary utf8-encoded characters. (On output, it's your job to verify that the output characters are indeed present in the font that's in use.) If the characters are TeX-special -- say, & and $ -- be sure to escape them as \\& and \\$, etc. Whitespace in the input string is preserved, but punctuation characters aren't given any preferential treatment.

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{luacode} % for 'luacode' environment and '\luastring' macro
\begin{luacode}
function rndstring ( inputstring )
local outputstring, choices, mm, nn
mm = unicode.utf8.len(inputstring) -- no. of utf8-encoded characters in input string
-- Place candidate replacement characters in a Lua table:
choices = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"\#", "\$", "\%", "\%", "\&", "\_", "\textbackslash{}",
"*", "+", "-", "/", "(", ")", "[", "]", "\{", "\}",
"<", "=", ">", "?", "@", "\textasciitilde{}",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
}
-- Number of rows in 'choices' table
nn = #choices
-- Generate the outputstring in a 'for' loop:
outputstring = ""
for i = 1 , mm do
if unicode.utf8.sub ( inputstring , i , i ) == " " then
outputstring = outputstring .. " " -- preserve space char.
else -- choose a new char randomly from 'choices' table
outputstring = outputstring .. choices[ math.random ( nn ) ]
end
end
return ( outputstring )
end
\end{luacode}
%% Define a LaTeX macro to invoke the Lua function
\newcommand\rndstring[1]{\directlua{tex.sprint(rndstring(\luastring{#1}))}}
%% test strings to feed to '\rndstring':
\newcommand\stringA{Hello World}
\newcommand\stringB{Hello Владимир öäüß}
\newcommand\stringC{Once upon a time, there was ...}
\begin{document}
\ttfamily % optional
\rndstring{\stringA}\par\rndstring{\stringB}\par\rndstring{\stringC}
\bigskip
\rndstring{\stringA}\par\rndstring{\stringB}\par\rndstring{\stringC}
\end{document}
tex.printthe results. – Skillmon Jan 30 '22 at 14:43&and$. – Mico Jan 30 '22 at 21:22