cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-439389%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EVerschl%C3%BCsseln%20und%20Entschl%C3%BCsseln%20mit%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-439389%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EIch%20versuche%2C%20eine%20Liste%20g%C3%BCltiger%20JSL%20mit%20runprogram%2Fpowershell%20zu%20verschl%C3%BCsseln.Aus%20Leistungsgr%C3%BCnden%20ist%20es%20wichtig%2C%20dass%20dies%20nur%20ein%20einziger%20Aufruf%20von%20Powershell%20ist.Ich%20dachte%2C%20ich%20h%C3%A4tte%20es%20geschafft%2C%20aber%20mir%20wurde%20klar%2C%20dass%20einfache%20oder%20doppelte%20Anf%C3%BChrungszeichen%20mich%20verwirren%2C%20wenn%20es%20sich%20um%20verschachtelte%20Listen%20handelt.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAu%C3%9Ferdem%20kann%20ich%20NICHT%20in%20eine%20Datei%20schreiben%20und%20diese%20von%20Powershell%20lesen%20lassen.funktioniert%20super%2C%20darf%20es%20aber%20nicht%20machen.Ich%20glaube%2C%20ich%20bin%20einfach%20kaputt%2C%20weil%20ich%20JSL%2C%20C%20und%20Powershell%20entkomme.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20default%20to%20here(1)%3B%0Aencryption_key%20%3D%20J(16%2C%201%2C%20randominteger(0%2C%20255))%3B%0Aunencrypted_input%20%3D%20%7B%22Fa'ke%5C!%22%22%2C%20%7BEmpty()%2C%20%22Str'%5C!%22ing%22%7D%7D%3B%20%2F%2F%20this%20one%20breaks%20me%0Aunencrypted_input%20%3D%20%7B%22Fake%22%2C%20%7BEmpty()%2C%20%22String%22%7D%7D%3B%20%2F%2F%20this%20one%20is%20fine%0A%0Aprint(%22encryptng%22)%3B%0Ainit_str%20%3D%20%22%40(%22%3B%20%2F%2F%20creating%20a%20powershell%20array%0Afor(i%3D1%2C%20i%26lt%3B%3Dnitems(unencrypted_input)%2C%20i%2B%2B%2C%20%0A%20if(i!%3D1%2C%20init_str%20%7C%7C%3D%20%22%2C%20%22)%3B%0A%20item%20%3D%20unencrypted_input%5Bi%5D%3B%0A%20%2F%2F%20for%20encrypt%20we%20want%20to%20put%20it%20in%20quotes%20so%20we%20can%20pull%20it%20out%20later%20so%20we%20can%20parse%3B%0A%20if(%20isstring(item)%2C%20item%20%3D%20%22%5C!%22%22%7C%7Cchar(item)%7C%7C%22%5C!%22%22)%3B%0A%20%2F%2F%20because%20of%20the%20way%20runprogram%20works%20we%20have%20to%20C%20escape%20the%20quotes%20as%20well%20%0A%20init_str%20%7C%7C%3D%20%22%5C%5C!%22%22%7C%7Csubstitute(char(item)%2C%20%22%5C!%22%22%2C%20%22'%22)%7C%7C%22%5C%5C!%22%22%3B%0A)%3B%0Ainit_str%20%7C%7C%3D%20%22)%22%3B%0A%0Aexec_str%20%3D%20init_str%20%7C%7C%20%22%20%7C%20ConvertTo-SecureString%20-AsPlainText%20-Force%22%0A%20%7C%7C%20%22%20%7C%20ConvertFrom-SecureString%20-Key%20%22%20%7C%7C%20Substitute(char(encryption_key)%2C%20%22%5B%22%2C%20%22(%22%2C%20%22%5D%22%2C%20%22)%22)%3B%0A%0Awrite(%22%5C!n%22%7C%7Cexec_str)%3B%0Arp%20%3D%20Run%20Program(%0A%20Executable(%22powershell%22)%2C%20%0A%20Options(exec_str)%2C%20%0A%20ReadFunction(%22text%22)%0A)%3B%0Aprint(%22%22)%3B%0Ashow(rp)%3B%0A%0Aencrypted_list%20%3D%20words(rp%2C%20%22%5C!n%5C!r%22)%3B%0A%0Aprint(%22decrypting%22)%3B%0A%2F%2F%20now%20to%20decrypt%0Ainit_str%20%3D%20%22%40(%22%3B%20%2F%2F%20creating%20a%20powershell%20array%0Afor(i%3D1%2C%20i%26lt%3B%3Dnitems(encrypted_list)%2C%20i%2B%2B%2C%20%0A%20if(i!%3D1%2C%20init_str%20%7C%7C%3D%20%22%2C%20%22)%3B%0A%20item%20%3D%20encrypted_list%5Bi%5D%3B%0A%20%2F%2F%20because%20of%20the%20way%20runprogram%20works%20we%20have%20to%20C%20escape%20the%20quotes%20as%20well%20%0A%20init_str%20%7C%7C%3D%20%22%5C%5C!%22%22%7C%7Csubstitute(char(item)%2C%20%22%5C!%22%22%2C%20%22'%22)%7C%7C%22%5C%5C!%22%22%3B%0A)%3B%0Ainit_str%20%7C%7C%3D%20%22)%22%3B%0A%0Aexec_str%20%3D%20init_str%20%7C%7C%20%22%20%7C%20ConvertTo-SecureString%20-Key%20%22%20%7C%7C%20Substitute(char(encryption_key)%2C%20%22%5B%22%2C%20%22(%22%2C%20%22%5D%22%2C%20%22)%22)%0A%20%7C%7C%20%22%20%7C%20ForEach-Object%20%7B%22%2F%2F%20doing%20this%20in%20a%20loop%20in%20case%20of%20multiple%20lines%0A%20%7C%7C%20%22%24BSTR%20%3D%20%5BSystem.Runtime.InteropServices.Marshal%5D%3A%3ASecureStringToBSTR(%24_)%3B%22%0A%20%7C%7C%20%22%5BSystem.Runtime.InteropServices.Marshal%5D%3A%3APtrToStringAuto(%24BSTR)%7D%22%3B%0A%20%0Awrite(%22%5C!n%22%7C%7Cexec_str)%3B%0Arp%20%3D%20Run%20Program(%0A%20Executable(%22powershell%22)%2C%20%0A%20Options(exec_str)%2C%20%0A%20ReadFunction(%22text%22)%0A)%3B%0Aprint(%22%22)%3B%0Ashow(rp)%3B%0Adec_list%20%3D%20Words(rp%2C%20%22%5C!n%5C!r%22)%3B%0Afor(i%3D1%2C%20i%26lt%3B%3Dnitems(dec_list)%2C%20i%2B%2B%2C%20%0A%20r%20%3D%20substitute(dec_list%5Bi%5D%2C%20%22'%22%2C%20%22%5C!%22%22)%3B%0A%20r%20%3D%20parse(r)%3B%20%2F%2F%20parse%20it%20because%20we%20wrapped%20everything%0A%20dec_list%5Bi%5D%20%3D%20r%3B%0A)%3B%0A%0Ashow(dec_list%2C%20unencrypted_input)%3B%0Ashow(dec_list%20%3D%3D%20unencrypted_input)%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-439389%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CLINGO-LABEL%3EQualit%C3%A4ts-%20und%20Verfahrenstechnik%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-439686%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Verschl%C3%BCsseln%20und%20Entschl%C3%BCsseln%20mit%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-439686%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EIch%20dachte%20eher%20an%20das%2C%20was%20unten%20steht%2C%20es%20sei%20denn%2C%20Sie%20m%C3%BCssen%20die%20%C3%A4u%C3%9Fere%20Listenstruktur%20in%20Powershell%20beibehalten%3FIch%20glaube%20nicht%2C%20dass%20Sie%20das%20Powershell-Array%20%C3%BCberhaupt%20ben%C3%B6tigen%2C%20es%20sei%20denn%2C%20die%20von%20Ihnen%20verwendete%20Verschl%C3%BCsselungsfunktion%20erfordert%20es.%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20default%20to%20here(1)%3B%0A%0Ato_pwsh_array%20%3D%20function(%7Binput%2C%20wrap_string%20%3D%201%7D%2C%20%0A%20%7BDEFAULT%20LOCAL%7D%2C%20%0A%20init_str%20%3D%20%22%40(%5C%5C!%22%22%20%7C%7C%20substitute(char(input)%2C%22%5C!%22%22%2C%22%5Bquote%5D%22)%20%7C%7C%20%22%5C%5C!%22)%22%3B%0A)%3B%0Afrom_pwsh_array%20%3D%20function(%7Binput%7D%2C%20%7Bdefault%20local%7D%2C%0A%20notrailingnewline%20%3D%20regex(rp%2C%22(.*)%5C!N%22%2C%22%5C1%22)%3B%0A%20replacedquotes%20%3D%20substitute(notrailingnewline%2C%20%22%5Bquote%5D%22%2C%20%22%5C!%22%22)%3B%0A%20parsed%20%3D%20parse(replacedquotes)%3B%0A%20parsed%3B%0A)%3B%0A%0Acheckvalue%20%3D%20function(%20%7Bin%7D%2C%0A%20rp%20%3D%20Run%20Program(%0A%20%20Executable(%22powershell%22)%2C%20%0A%20%20Options(to_pwsh_array(in))%2C%20%0A%20%20ReadFunction(%22text%22)%0A%20)%3B%0A%20out%20%3D%20from_pwsh_array(rp)%3B%0A%20show(in%2C%20to_pwsh_array(in)%2C%20rp%2C%20out%2C%20in%20%3D%3D%20out)%3B%0A%20in%20!%3D%20out%3B%0A)%3B%0A%0Aif(%20%0A%20sum(%0A%20%20checkvalue(%20Expr(%20%7B%22Fake%22%2C%20%7BEmpty()%2C%20%22String%22%7D%7D%20)%20)%3B%20%0A%20%20checkvalue(%20Expr(%20%7B%22Fa'ke%5C!%22%22%2C%20%7BEmpty()%2C%20%22Str'%5C!%22ing%22%7D%7D%20)%20)%3B%20%0A%20)%20%26gt%3B%200%2C%0A%20write(%22%5C!N%5C!NFailed%22)%2C%20%0A%20write(%22%5C!N%5C!NSuccess%22)%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-439666%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Verschl%C3%BCsseln%20und%20Entschl%C3%BCsseln%20mit%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-439666%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EIch%20habe%20versucht%2C%20das%20mit%20%5BZitat%5D%20zu%20machen%2C%20konnte%20es%20aber%20aufgrund%20der%20Art%20und%20Weise%2C%20wie%20char(Liste%20mit%20Zeichenfolgen)%20funktioniert%2C%20nicht%20zum%20Laufen%20bringen.Ich%20kann%20Powershell%20nicht%20dazu%20bringen%2C%20mir%20Anf%C3%BChrungszeichen%20zur%C3%BCckzugeben%2C%20es%20entfernt%20nur%20die%20Anf%C3%BChrungszeichen.%20Wenn%20ich%20es%20also%20wieder%20einziehe%20(wenn%20es%20auch%20Anf%C3%BChrungszeichen%20enth%C3%A4lt)%2C%20vermasselt%20es%20die%20Analyse.Ich%20k%C3%B6nnte%20vielleicht%20eine%20rekursive%20Funktion%20mit%20Tiefe%20erstellen%2C%20die%20alle%20Dinge%20in%20das%20umwandelt%2C%20was%20ich%20brauche%2C%20und%20dann%20nur%20die%20oberste%20Ebene%20umschlie%C3%9Ft.Falls%20das%20irgendeinen%20Sinn%20ergibt.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20default%20to%20here(1)%3B%0All%20%3D%20%7B%22Fak'e%5C!%22%22%2C%20%7BEmpty()%2C%20%22Str'%5C!%22ing%22%7D%7D%3B%0Achar(ll)%3B%20%2F%2F%20%22%7B%5C!%22Fak'e%5C!%5C!%5C!%22%5C!%22%2C%20%7BEmpty()%2C%20%5C!%22Str'%5C!%5C!%5C!%22ing%5C!%22%7D%7D%22%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-439646%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Verschl%C3%BCsseln%20und%20Entschl%C3%BCsseln%20mit%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-439646%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EK%C3%B6nnten%20Sie%20die%20Anf%C3%BChrungszeichen%20in%20JSL%20durch%20etwas%20ersetzen%2C%20das%20kein%20Anf%C3%BChrungszeichen%20enth%C3%A4lt%2C%20und%20sie%20dann%20mithilfe%20von%20Ersetzen%20wieder%20in%20Powershell%20ersetzen%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-439475%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Verschl%C3%BCsseln%20und%20Entschl%C3%BCsseln%20mit%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-439475%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EIch%20denke%2C%20der%20Knackpunkt%20liegt%20darin%2C%20zu%2Fvon%20einem%20Powershell-Array%20zu%20wechseln.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EVielleicht%20erleichtert%20das%20das%20Verst%C3%A4ndnis%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20default%20to%20here(1)%3B%0A%2F%2Funencrypted_input%20%3D%20%7B%22Fa'ke%5C!%22%22%2C%20%7BEmpty()%2C%20%22Str'%5C!%22ing%22%7D%7D%3B%20%2F%2F%20this%20one%20breaks%20me%0Aunencrypted_input%20%3D%20%7B%22Fake%22%2C%20%7BEmpty()%2C%20%22String%22%7D%7D%3B%20%2F%2F%20this%20one%20is%20fine%0Ato_pwsh_array%20%3D%20function(%7Binput%2C%20wrap_string%20%3D%201%7D%2C%20%0A%20%2F%2F%20wrap%20string%20because%20the%20inputs%20for%20decrypt%20aren't%20valid%20JSL%20so%20we%20don't%20want%20to%20wrap%20those%0A%20%7BDEFAULT%20LOCAL%7D%2C%20%0A%20init_str%20%3D%20%22%40(%22%3B%20%2F%2F%20creating%20a%20powershell%20array%0A%20for(i%3D1%2C%20i%26lt%3B%3Dnitems(input)%2C%20i%2B%2B%2C%20%0A%20%20if(i!%3D1%2C%20init_str%20%7C%7C%3D%20%22%2C%20%22)%3B%0A%20%20item%20%3D%20input%5Bi%5D%3B%0A%20%20%2F%2F%20for%20encrypt%20we%20want%20to%20put%20it%20in%20quotes%20so%20we%20can%20pull%20it%20out%20later%20so%20we%20can%20parse%3B%0A%20%20if(%20wrap_string%20%26amp%3B%20isstring(item)%2C%20item%20%3D%20%22%5C!%22%22%7C%7Cchar(item)%7C%7C%22%5C!%22%22)%3B%0A%20%20%2F%2F%20because%20of%20the%20way%20runprogram%20works%20we%20have%20to%20C%20escape%20the%20quotes%20as%20well%20%0A%20%20init_str%20%7C%7C%3D%20%22%5C%5C!%22%22%7C%7Csubstitute(char(item)%2C%20%22%5C!%22%22%2C%20%22'%22)%7C%7C%22%5C%5C!%22%22%3B%0A%20)%3B%0A%20init_str%20%7C%7C%3D%20%22)%22%3B%0A)%3B%0Afrom_pwsh_array%20%3D%20function(%7Binput%7D%2C%20%0A%20final_list%20%3D%20Words(input%2C%20%22%5C!n%5C!r%22)%3B%0A%20for(i%3D1%2C%20i%26lt%3B%3Dnitems(final_list)%2C%20i%2B%2B%2C%20%0A%20%20r%20%3D%20substitute(final_list%5Bi%5D%2C%20%22'%22%2C%20%22%5C!%22%22)%3B%0A%20%20r%20%3D%20parse(r)%3B%20%2F%2F%20parse%20it%20because%20we%20wrapped%20everything%0A%20%20final_list%5Bi%5D%20%3D%20r%3B%0A%20)%3B%0A%20return(final_list)%3B%0A)%3B%0A%0Arp%20%3D%20Run%20Program(%0A%20Executable(%22powershell%22)%2C%20%0A%20Options(to_pwsh_array(unencrypted_input))%2C%20%0A%20ReadFunction(%22text%22)%0A)%3B%0A%0Aout%20%3D%20from_pwsh_array(rp)%3B%0A%0Ashow(out%20%3D%3D%20unencrypted_input)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
vince_faller
Super User (Alumni)

Encrypting Decrypting with Powershell

I'm trying to encrypt a list of valid JSL using runprogram/powershell.  It's important that this is only a single call to powershell because of performance.  I thought I had it working but realized that single or double quotes messes me up when they're nested lists.  

Also, I can NOT write to a file and have powershell read that.  works great, not allowed to do it though.  I think I'm just broken on the escaping of JSL and C and Powershell. 

 

Names default to here(1);
encryption_key = J(16, 1, randominteger(0, 255));
unencrypted_input = {"Fa'ke\!"", {Empty(), "Str'\!"ing"}}; // this one breaks me
unencrypted_input = {"Fake", {Empty(), "String"}}; // this one is fine

print("encryptng");
init_str = "@("; // creating a powershell array
for(i=1, i<=nitems(unencrypted_input), i++, 
	if(i!=1, init_str ||= ", ");
	item = unencrypted_input[i];
	// for encrypt we want to put it in quotes so we can pull it out later so we can parse;
	if( isstring(item), item = "\!""||char(item)||"\!"");
	// because of the way runprogram works we have to C escape the quotes as well	
	init_str ||= "\\!""||substitute(char(item), "\!"", "'")||"\\!"";
);
init_str ||= ")";

exec_str = init_str || " | ConvertTo-SecureString -AsPlainText -Force"
	|| " | ConvertFrom-SecureString -Key " || Substitute(char(encryption_key), "[", "(", "]", ")");

write("\!n"||exec_str);
rp = Run Program(
	Executable("powershell"), 
	Options(exec_str), 
	ReadFunction("text")
);
print("");
show(rp);

encrypted_list = words(rp, "\!n\!r");

print("decrypting");
// now to decrypt
init_str = "@("; // creating a powershell array
for(i=1, i<=nitems(encrypted_list), i++, 
	if(i!=1, init_str ||= ", ");
	item = encrypted_list[i];
	// because of the way runprogram works we have to C escape the quotes as well	
	init_str ||= "\\!""||substitute(char(item), "\!"", "'")||"\\!"";
);
init_str ||= ")";

exec_str = init_str || " | ConvertTo-SecureString -Key " || Substitute(char(encryption_key), "[", "(", "]", ")")
	|| " | ForEach-Object {"// doing this in a loop in case of multiple lines
	|| "$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($_);"
	|| "[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)}";
	
write("\!n"||exec_str);
rp = Run Program(
	Executable("powershell"), 
	Options(exec_str), 
	ReadFunction("text")
);
print("");
show(rp);
dec_list = Words(rp, "\!n\!r");
for(i=1, i<=nitems(dec_list), i++, 
	r = substitute(dec_list[i], "'", "\!"");
	r = parse(r); // parse it because we wrapped everything
	dec_list[i] = r;
);

show(dec_list, unencrypted_input);
show(dec_list == unencrypted_input);
Vince Faller - Predictum
4 REPLIES 4
vince_faller
Super User (Alumni)

Re: Encrypting Decrypting with Powershell

I think the crux is with going to/from a powershell array.  

 

Maybe this makes things easier to understand

 

 

Names default to here(1);
//unencrypted_input = {"Fa'ke\!"", {Empty(), "Str'\!"ing"}}; // this one breaks me
unencrypted_input = {"Fake", {Empty(), "String"}}; // this one is fine
to_pwsh_array = function({input, wrap_string = 1}, 
	// wrap string because the inputs for decrypt aren't valid JSL so we don't want to wrap those
	{DEFAULT LOCAL}, 
	init_str = "@("; // creating a powershell array
	for(i=1, i<=nitems(input), i++, 
		if(i!=1, init_str ||= ", ");
		item = input[i];
		// for encrypt we want to put it in quotes so we can pull it out later so we can parse;
		if( wrap_string & isstring(item), item = "\!""||char(item)||"\!"");
		// because of the way runprogram works we have to C escape the quotes as well	
		init_str ||= "\\!""||substitute(char(item), "\!"", "'")||"\\!"";
	);
	init_str ||= ")";
);
from_pwsh_array = function({input}, 
	final_list = Words(input, "\!n\!r");
	for(i=1, i<=nitems(final_list), i++, 
		r = substitute(final_list[i], "'", "\!"");
		r = parse(r); // parse it because we wrapped everything
		final_list[i] = r;
	);
	return(final_list);
);

rp = Run Program(
	Executable("powershell"), 
	Options(to_pwsh_array(unencrypted_input)), 
	ReadFunction("text")
);

out = from_pwsh_array(rp);

show(out == unencrypted_input);
Vince Faller - Predictum
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Encrypting Decrypting with Powershell

Could you substitute the quotes in JSL with something that doesn't include a quote and then substitute them back within powershell using replace?

vince_faller
Super User (Alumni)

Re: Encrypting Decrypting with Powershell

I tried to do that with [quote], but I couldn't get it to work because of the the way char(list containing strings) works.  I can't get powershell to give me quotes back, it just strips the quotes, so when I pull it back in (if it has quotes inside as well) then it screws up the parse.  I could maybe make a recursive function with depth so that it goes in and turns all things into what I need then only wrap the top level.  If that makes any sense.  

 

Names default to here(1);
ll = {"Fak'e\!"", {Empty(), "Str'\!"ing"}};
char(ll); // "{\!"Fak'e\!\!\!"\!", {Empty(), \!"Str'\!\!\!"ing\!"}}"

 

 

 

Vince Faller - Predictum
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Encrypting Decrypting with Powershell

I was thinking more like what is below, unless you need to keep the outer list structure in powershell?  I don't think you even need the powershell array unless the encryption function you're using requires it.

Names default to here(1);

to_pwsh_array = function({input, wrap_string = 1}, 
	{DEFAULT LOCAL}, 
	init_str = "@(\\!"" || substitute(char(input),"\!"","[quote]") || "\\!")";
);
from_pwsh_array = function({input}, {default local},
	notrailingnewline = regex(rp,"(.*)\!N","\1");
	replacedquotes = substitute(notrailingnewline, "[quote]", "\!"");
	parsed = parse(replacedquotes);
	parsed;
);

checkvalue = function( {in},
	rp = Run Program(
		Executable("powershell"), 
		Options(to_pwsh_array(in)), 
		ReadFunction("text")
	);
	out = from_pwsh_array(rp);
	show(in, to_pwsh_array(in), rp, out, in == out);
	in != out;
);

if( 
	sum(
		checkvalue( Expr( {"Fake", {Empty(), "String"}} ) ); 
		checkvalue( Expr( {"Fa'ke\!"", {Empty(), "Str'\!"ing"}} ) ); 
	) > 0,
	write("\!N\!NFailed"), 
	write("\!N\!NSuccess")
);

Recommended Articles