How can I decrypt this simple XOR encryption for Lua Script? - encryption

key=gg.prompt({"Enter Password"},{""},{"text"})
[1]local a=load((function(b,c)function bxor(d,e)local f={{0,1},{1,0}}
local g=1;local h=0;
while d>0 or e>0 do h=h+f[d%2+1][e%2+1]*g;
d=math.floor(d/2)e=math.floor(e/2)g=g*2 end;
return h end;
local i=function(b)
local j={}
local k=1;
local l=b[k]
while l>=0 do j[k]=b[l+1]k=k+1;
l=b[k]end;
return j end;
local m=function(b,c)if#c<=0 then return{}end;
local k=1;
local n=1;
for k=1,#b do b[k]=bxor(b[k],string.byte(c,n))n=n+1;
if n>#c then n=1 end end;
return b end;
local o=function(b)local j=""for k=1,#b do j=j..string.char(b[k])end;
return j end;
return o(m(i(b),c))end)
({150642,122783,122295,135436,146969,90016,86043,150619,80488,111860,122502,86813,106235,136554,126669},key))
if a then a()else gg.alert("Wrong Password")end
Can I get the code which can simply decrypt the ciphertext which is encrypted by the above code.

Related

How to debug an Ada program?

I did the problem and when I try to compile it said that identifier expected but I did all right.
with.Ada.TexT_IO;use Ada.Text_IO;
Procedure Isort1 is
type node;
type link is access node;
type node is
record
value:integer;
rest:Character;
next:link;
end record;
package IntIO is new Ada.Text_IO.Integer_IO(integer);use IntIO;
int:integer;
l:link;
pt:array(1..100)of link;
ch:character;
begin
for i in 1..10 loop pt(i):=null;
end loop;
loop
put("put an integer key (1 thru 10),99 to stop ");
get(int);
exit when int=99;
put("enter the other info,1 char ");
get(ch);
pt(int):= new node'(int,ch,pt(int));
end loop;
for i in 1..10 loop
i:=pt(i);
while I /=null loop
put(I.value);
put("... ");
put(I.rest);
new_line;
I:=I.next;
end loop;
end loop;
end Isort1;
Your assumption that you "did all right" is clearly wrong.
It appears that you are learning Ada after knowing some other programming language. You appear to be mixing ideas from other language(s) into your Ada code.
Let's organize and indent your code first.
with.Ada.TexT_IO;use Ada.Text_IO;
Procedure Isort1 is
type node;
type link is access node;
type node is
record
value:integer;
rest:Character;
next:link;
end record;
package IntIO is new Ada.Text_IO.Integer_IO(integer);use IntIO;
int:integer;
l:link;
pt:array(1..100)of link;
ch:character;
begin
for i in 1..10 loop pt(i):=null;
end loop;
loop
put("put an integer key (1 thru 10),99 to stop ");
get(int);
exit when int=99;
put("enter the other info,1 char ");
get(ch);
pt(int):= new node'(int,ch,pt(int));
end loop;
for i in 1..10 loop
i:=pt(i);
while I /=null loop
put(I.value);
put("... ");
put(I.rest);
new_line;
I:=I.next;
end loop;
end loop;
end Isort1;
Your first line begins with "with.Ada.TexT_IO;". It should say "with Ada.Text_I0;". Capitalization differences are not the problem. The problem is the period '.' following the reserved word "with".
Once that problem is fixed the compiler will tell you that you have an error in the line containing
i:=pt(i);
The error messages from the compiler are shown in the screen capture below.
It appears that you want the variable I to contain an instance of type node, but variable I is never declared and is never assigned a value.

How to resolve "Error 200: Division by zero"?

I've FreeDos OS installed on VirtualBox on a windows xp, dual core, host machine. I installed FreeDos because I wanted to run a Pascal code using Turbo Pascal. When I run the code, it throws error 'Error 200: Division by zero.'. How can I solve this?
-Turbo Pascal 7.0, Free DOS 1.1, Virtual Box 4.3.6, Windows XP Service Pack 3 Host machine
-This error is unfortunately caused by fast Pentium CPUs and I found a patch on the internet that will resolve the error. (www.filewatcher.com/m/bp7patch.zip.62550-0.html) Now the other problem is, when i was tracing the code, it hangs at 'RxWait procedure when trying to execute while not odd(port[RXTX + 5]) do;'
uses crt;
const
{ COM1: RS232 port address }
RXTX = $3F8; { $2F8 if COM2: is used }
ACK = 6;
NAK = 21;
ESC = 27;
var
dummy,
checkSum : integer;
key : char;
protocol : integer;
procedure InitComm;
{ Set baudrate to 9600, 8 bits, no parity, 1 stop bit }
var i : integer;
begin
i := 1843200 div 9600 div 16;
port[RXTX + 3] := $80;
port[RXTX + 1] := hi(i);
port[RXTX]:= lo(i);
port[RXTX + 3] := 3;
port[RXTX + 4] := $A;
while odd(port[RXTX + 5]) do
begin
dummy := port[RXTX];
delay(10);
end;
end; { InitComm }
procedure Tx(data : integer);
{ Transmit a character on serial channel }
begin
while port[RXTX + 5] and $20 = 0 do;
port[RXTX] := data and $FF;
end; { Tx }
function RxWait : integer;
{ Waits for a character from serial channel }
begin
while not odd(port[RXTX + 5]) do;
RxWait := port[RXTX];
end; { RxWait }
procedure Tx2(data : integer);
{ Transmit a char on serial channel + Calculate check sum }
begin
Tx(data);
checkSum := (checkSum + data) and $FF;
end; { Tx2 }
procedure TxCommand(c1, c2 : char;
sendCheckSum : boolean);
{ Transmit command (no data) on serial channel }
begin
Tx(ESC);
checkSum := 0;
Tx2(ord(c1));
Tx2(ord(c2));
if sendCheckSum then
begin
Tx2(checkSum);
dummy := RxWait;
end;
end; { TxCommand }
function ReadNumber(n : integer) : real;
{ Read n bytes from serial channel }
var
number: real;
i : integer;
begin
number := 0;
checkSum := 0;
for i := 1 to n do
number := number * 256 + RxWait;
dummy := RxWait;
ReadNumber := number;
end; { ReadNumber }
procedure Revisions;
var
tmp : integer;
sw,
prot : real;
begin
TxCommand('P', 'R', FALSE);
checkSum := 0;
tmp := RxWait;
sw := tmp + RxWait / 100.0;
protocol := RxWait;
prot := protocol + RxWait / 100.0;
dummy := RxWait;
tmp := RxWait;
writeln('Software revision: ', sw:4:2);
writeln('Protocol revision: ', prot:4:2);
end; { Revisions }
procedure ReadCountReg;
begin
TxCommand('R', 'C', FALSE);
writeln(ReadNumber(4):11:0, ' coins counted.');
dummy := RxWait;
end; { ReadCountReg }
procedure ReadAccReg;
begin
TxCommand('R', 'A', FALSE);
writeln(ReadNumber(4):11:0, ' coins in accumulator.');
dummy := RxWait;
end; { ReadAccReg }
procedure Setbatch(limit : longint);
begin
TxCommand('W', 'L', FALSE);
case protocol of
1 : begin
Tx2(limit div 256);
Tx2(limit mod 256);
end;
2 : begin
Tx2( limit div 16777216);
Tx2((limit div 65536) mod 256);
Tx2((limit div 256) mod 256);
Tx2( limit mod 256);
end;
end; { case protocol }
Tx2(checkSum);
dummy := RxWait;
end; { Setbatch }
As far as I remember (more than 12 years ago), CRT unit had problems about Pentium CPUs and giving that division by zero error. I was using Turbo Pascal 7 those days. What I mean is that it may not be your coding error, but just CRT unit itself.
Old question I know, but there is another way to write Turbo Pascal code without incurring the wrath of the infamous RTE 200 bug. FreePascal (www.freepascal.org) is fully TP7 compatible and runs under a number of OSes including DOS, Windows and Linux.
Hope this helps!
I solved it setting the Execution Cap to 20%. So the processor is probably as slower as expected in those days. You can play with percentages until the error disappear
Regards

Windows CE Programming Serial Port - Getting Garbled Output

I am programming a Windows CE 6 device (Motorola MC3100 scanner Terminal). Using Lazarus FPC to compile it.
After 3 weeks work I reluctantly post here in the hope someone can suggest why I am getting garbled output from the serial port.
The code I am using is posted below. This is the standard code I have found from several places.
The OpenPort works OK.
When I send the string using SendString('ABCDEF') I get garbled input to the PC Serial port such as:
4[#131][#26][#0][#0][#0][#0] (the bracketed data indicates that it is a non-printable character ASCII Code)
Obviously it is connecting to the port OK AND it is sending the correct no of characters (7).
I have tried all combinations of Baud Rate, Data Bits, Parity and Stop Bits without any joy. Also tried changing cable, on a different PC etc.
Could it be I need to set something else in the DCB?
Any help or suggestions would be GREATLY appreciated.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
Windows, LResources;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
function OpenPort(ComPort:String;BaudRate,ByteSize,Parity,StopBits:integer):String;
procedure SendString(str:String);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
cc:TCOMMCONFIG;
Connected:Boolean;
implementation
{$R *.lfm}
var F: TextFile;
var hComm: THandle;
str: String;
lrc: LongWord;
{ TForm1 }
function
OpenPort(ComPort:String;BaudRate,ByteSize,Parity,StopBits:integer):String;
var
cc:TCOMMCONFIG;
SWide:WideString;
Port:LPCWSTR;
begin
SWide:=ComPort;
Port:=PWideChar(SWide);
result:='';
if (1=1) then begin
Connected:=False;
hComm:=CreateFile(Port, GENERIC_READ or GENERIC_WRITE,0, nil,OPEN_EXISTING,0,0);
if (hComm = INVALID_HANDLE_VALUE) then begin
ShowMessage('Fail to Open');
exit;
end;
GetCommState(hComm,cc.dcb);
cc.dcb.BaudRate:=BaudRate;
cc.dcb.ByteSize:=ByteSize;
cc.dcb.Parity:=Parity;
cc.dcb.StopBits:=StopBits;
if not SetCommState(hComm, cc.dcb) then begin
result:='SetCommState Error!';
CloseHandle(hComm);
exit;
end;
Connected:=True;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenPort('COM1:',9600,8,0,0);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SendString('ABCDEFG');
end;
procedure TForm1.SendString(str:String);
var
lrc:LongWord;
begin
if (hComm=0) then exit;
try
if not PurgeComm(hComm, PURGE_TXABORT or PURGE_TXCLEAR) then
raise Exception.Create('Unable to purge com: ');
except
Exit;
end;
WriteFile(hComm,str,Length(str), lrc, nil);
end;
end.
Found the answer to this.
WriteFile(hComm,str,Length(str), lrc, nil);
The "str" parameter was in fact a pointer to the string, not the string itself
Changing it to this works.
WriteFile(hComm,str[1],Length(str), lrc, nil);

Inno Setup Windows DLL function call with pointer to structure

I am trying to set a service's failure actions using Inno Setup's Pascal scripting language. I receive the classic "access violation at address..." error. Seems that it is impossible because the language don't have any support to pointers. Any ideas? Here is the code snippet:
type
TScAction = record
aType1 : Longword;
Delay1 : Longword;
aType2 : Longword;
Delay2 : Longword;
aType3 : Longword;
Delay3 : Longword;
end;
type
TServiceFailureActionsA = record
dwResetPeriod : DWORD;
pRebootMsg : String;
pCommand : String;
cActions : DWORD;
saActions : TScAction;
end;
function ChangeServiceConfig2(hService: Longword; dwInfoLevel: Longword; lpInfo: TServiceFailureActionsA): BOOL;
external 'ChangeServiceConfig2A#advapi32.dll stdcall';
procedure SimpleChangeServiceConfig(AService: string);
var
SCMHandle: Longword;
ServiceHandle: Longword;
sfActions: TServiceFailureActionsA;
sActions: TScAction;
begin
try
SCMHandle := OpenSCManager('', '', SC_MANAGER_ALL_ACCESS);
if SCMHandle = 0 then
RaiseException('SimpleChangeServiceConfig#OpenSCManager: ' + AService + ' ' +
SysErrorMessage(DLLGetLastError));
try
ServiceHandle := OpenService(SCMHandle, AService, SERVICE_ALL_ACCESS);
if ServiceHandle = 0 then
RaiseException('SimpleChangeServiceConfig#OpenService: ' + AService + ' ' +
SysErrorMessage(DLLGetLastError));
try
sActions.aType1 := SC_ACTION_RESTART;
sActions.Delay1 := 60000; // First.nDelay: in milliseconds, MMC displayed in minutes
sActions.aType2 := SC_ACTION_RESTART;
sActions.Delay2 := 60000;
sActions.aType3 := SC_ACTION_RESTART;
sActions.Delay3 := 60000;
sfActions.dwResetPeriod := 1; // in seconds, MMC displayes in days
//sfActions.pRebootMsg := null; // reboot message unchanged
//sfActions.pCommand := null; // command line unchanged
sfActions.cActions := 3; // first, second and subsequent failures
sfActions.saActions := sActions;
if not ChangeServiceConfig2(
ServiceHandle, // handle to service
SERVICE_CONFIG_FAILURE_ACTIONS, // change: description
sfActions) // new description
then
RaiseException('SimpleChangeServiceConfig#ChangeServiceConfig2: ' + AService + ' ' +
SysErrorMessage(DLLGetLastError));
finally
if ServiceHandle <> 0 then
CloseServiceHandle(ServiceHandle);
end;
finally
if SCMHandle <> 0 then
CloseServiceHandle(SCMHandle);
end;
except
ShowExceptionMessage;
end;
end;
You have two problems in your script. Like Deanna suggested you have to use the var keyword in the declaration of the lpInfo parameter.
Also you need to change the TScAction type to an array with two elements.
Here is my script that you can include in your Inno Setup script.
const
SERVICE_CONFIG_DELAYED_AUTO_START_INFO = 3; //The lpInfo parameter is a pointer to a SERVICE_DELAYED_AUTO_START_INFO structure.
//Windows Server 2003 and Windows XP: This value is not supported.
SERVICE_CONFIG_DESCRIPTION = 1; //The lpInfo parameter is a pointer to a SERVICE_DESCRIPTION structure.
SERVICE_CONFIG_FAILURE_ACTIONS = 2; //The lpInfo parameter is a pointer to a SERVICE_FAILURE_ACTIONS structure.
//If the service controller handles the SC_ACTION_REBOOT action, the caller must have
// the SE_SHUTDOWN_NAME privilege. For more information, see Running with Special Privileges.
SERVICE_CONFIG_FAILURE_ACTIONS_FLAG = 4; //The lpInfo parameter is a pointer to a SERVICE_FAILURE_ACTIONS_FLAG structure.
//Windows Server 2003 and Windows XP: This value is not supported.
SERVICE_CONFIG_PREFERRED_NODE = 9; //The lpInfo parameter is a pointer to a SERVICE_PREFERRED_NODE_INFO structure.
//Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP: This value is not supported.
SERVICE_CONFIG_PRESHUTDOWN_INFO = 7; //The lpInfo parameter is a pointer to a SERVICE_PRESHUTDOWN_INFO structure.
//Windows Server 2003 and Windows XP: This value is not supported.
SERVICE_CONFIG_REQUIRED_PRIVILEGES_INFO = 6; //The lpInfo parameter is a pointer to a SERVICE_REQUIRED_PRIVILEGES_INFO structure.
//Windows Server 2003 and Windows XP: This value is not supported.
SERVICE_CONFIG_SERVICE_SID_INFO = 5; //The lpInfo parameter is a pointer to a SERVICE_SID_INFO structure.
SERVICE_CONFIG_TRIGGER_INFO = 8; //The lpInfo parameter is a pointer to a SERVICE_TRIGGER_INFO structure.
//This value is not supported by the ANSI version of ChangeServiceConfig2.
//Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP: This value is not supported until Windows Server 2008 R2.
SC_ACTION_NONE = 0; // No action.
SC_ACTION_REBOOT = 2; // Reboot the computer.
SC_ACTION_RESTART = 1; // Restart the service.
SC_ACTION_RUN_COMMAND = 3; // Run a command.
type
TScAction = record
aType1 : Longword;
Delay1 : Longword;
end;
type
TServiceFailureActionsA = record
dwResetPeriod : DWORD;
pRebootMsg : String;
pCommand : String;
cActions : DWORD;
saActions : array of TScAction;
end;
function ChangeServiceConfig2(
hService: Longword;
dwInfoLevel: Longword;
var lpInfo: TServiceFailureActionsA): BOOL;
external 'ChangeServiceConfig2A#advapi32.dll stdcall';
procedure SimpleChangeServiceConfig(AService: string);
var
SCMHandle: Longword;
ServiceHandle: Longword;
sfActions: TServiceFailureActionsA;
sActions: array of TScAction;
begin
SetArrayLength(sActions ,3);
try
SCMHandle := OpenSCManager('', '', SC_MANAGER_ALL_ACCESS);
if SCMHandle = 0 then
RaiseException('SimpleChangeServiceConfig#OpenSCManager: ' + AService + ' ' +
SysErrorMessage(DLLGetLastError));
try
ServiceHandle := OpenService(SCMHandle, AService, SERVICE_ALL_ACCESS);
if ServiceHandle = 0 then
RaiseException('SimpleChangeServiceConfig#OpenService: ' + AService + ' ' +
SysErrorMessage(DLLGetLastError));
try
sActions[0].aType1 := SC_ACTION_RESTART;
sActions[0].Delay1 := 60000; // First.nDelay: in milliseconds, MMC displayed in minutes
sActions[1].aType1 := SC_ACTION_RESTART;
sActions[1].Delay1 := 60000;
sActions[2].aType1 := SC_ACTION_NONE;
sActions[2].Delay1 := 60000;
sfActions.dwResetPeriod := 1; // in seconds, MMC displayes in days
//sfActions.pRebootMsg := null; // reboot message unchanged
//sfActions.pCommand := null; // command line unchanged
sfActions.cActions := 3; // first, second and subsequent failures
sfActions.saActions := sActions;
if not ChangeServiceConfig2(
ServiceHandle, // handle to service
SERVICE_CONFIG_FAILURE_ACTIONS, // change: description
sfActions) // new description
then
RaiseException('SimpleChangeServiceConfig#ChangeServiceConfig2: ' + AService + ' ' +
SysErrorMessage(DLLGetLastError));
finally
if ServiceHandle <> 0 then
CloseServiceHandle(ServiceHandle);
end;
finally
if SCMHandle <> 0 then
CloseServiceHandle(SCMHandle);
end;
except
ShowExceptionMessage;
end;
end;
Try using the var keyword in the declaration for the lpInfo parameter to specify that it's to pass a pointer to the structure to the function.

Are there any differences between these two files?

I have two ada files shown below
A1.ada
procedure KOR616 is
I : Integer := 3;
procedure Lowest_Level( Int : in out Integer );
pragma Inline( Lowest_Level );
procedure Null_Proc is
begin
null;
end;
procedure Lowest_Level( Int : in out Integer ) is
begin
if Int > 0 then
Int := 7;
Null_Proc;
else
Int := Int + 1;
end if;
end;
begin
while I < 7 loop
Lowest_Level( I );
end loop;
end;
Next shown below is B1.ada
procedure Lowest_Level( Int : in out Integer );
pragma Inline( Lowest_Level );
procedure Lowest_Level( Int : in out Integer ) is
procedure Null_Proc is
begin
null;
end;
begin
if Int > 0 then
Int := 7;
Null_Proc;
else
Int := Int + 1;
end if;
end Lowest_Level;
with Lowest_Level;
procedure KOR618 is
I : Integer := 3;
begin
while I < 7 loop
Lowest_Level( I );
end loop;
end;
Is there any difference between these two files?
As written, KOR616 (A1) and KOR618 (B1) are going to have the same effect. The difference is a matter of visibility (and the compiled code will be different, of course, but I doubt that matters).
In A1, the bodies of both Null_Proc and Lowest_Level can see I, but nothing outside KOR616 can see them. Also, the body of KOR616 can see Null_Proc.
In B1, Lowest_Level (but not Null_Proc) is visible to the whole program, not just KOR618.
In B1, Null_Proc isn't inlined. (It is not within Lowest_Level).
In A1, procedure Null_Proc is not nested in procedure Lowest_Level; in B1, it is nested in procedure Lowest_Level. Regarding pragma Inline, "an implementation is free to follow or to ignore the recommendation expressed by the pragma." I'd expect the in-lining of nested subprograms to be implementation dependent.
Well, the main difference is that in the second example Null_Proc is unavailable outside of Lowest_Level. In the first example, if you felt like it later you could have KOR618 or any other routine you might add later also call Null_Proc.
Generally I don't define routines inside other routines like that unless there is some reason why the inner routine makes no sense outside of the outer routine. The obvious example would be if the inner routine operates on local variables declared in the outer routine (without passing them as parameters).
In this case Null_Proc is about as general an operation as it gets, so I don't see any compelling reason to squirel it away inside Lowest_Level like that. Of course, it doesn't do anything at all, so I don't any compelling reason for it to exist in the first place. :-)

Resources