Results 1 to 16 of 16

Thread: string variable manipulation?

  1. #1
    Join Date
    Jun 2006
    Posts
    89
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default string variable manipulation?

    ok, couldnt think of a better title...

    here is what i need to do, and i have no idea how

    i have the variable a, it is a string containing 'Test'
    i want the script to take that, and change each letter into a different one, like a=z's, b=y's, and etc

    how would i do that? is it possilbe?

  2. #2
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    PHP Code:
    function encode(a,b:char;str:String):String;
    var
    i:integer;
    strdone:String;
    begin
    for i:=1 to Length(str) do
    begin
    if(str[i]=a)then    //the letter being replaced
    strdone:=strdone+b//the letter you want to replace it as
    if(not(str[i]=a))then
    strdone
    :=strdone+str[i];
    end;
    result:=strdone;
    end
    ^^paste that in after 'Program New...'

    Use it like this -
    encode('a','b','string to encode');
    'a' is the letter being changed
    'b' is what it is being changed to

    if you want to encode multiple letters, you could do it like this->
    writeln(encode('a','b',encode('m','n','hey mom look at this!')))
    Interested in C# and Electrical Engineering? This might interest you.

  3. #3
    Join Date
    Feb 2007
    Location
    USA
    Posts
    667
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Is this how the obfuscator works?

  4. #4
    Join Date
    Jun 2006
    Posts
    89
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    not really to the obfu. i know that... how would i make it do every letter, and every number?

    i think its kinda sad that i don't understand how that code works either, and im a good scar scripter, just couldnt figure this out

  5. #5
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Use 2 arrays.

    Edit: actually you kinda need 3

    SCAR Code:
    program New;
    {.include SRL/SRL.scar}
    function encode(a,b:string;str:String):String;
    var
    i:integer;
    strdone:String;
    begin
    for i:=1 to Length(str) do
    begin
    if(str[i]=a)then    //the letter being replaced
    strdone:=strdone+b; //the letter you want to replace it as
    if(not(str[i]=a))then
    strdone:=strdone+str[i];
    end;
    result:=strdone;
    end;

    function encodeall(WhatToEncode:string):string;
    var
      PlainText,CipherText:array of string;
      iter:integer;
    begin
      PlainText:=['a','b','c','d']
      CipherText:=['c','d','b','a']
      result:=WhatToEncode;
      for iter:=0 to getarraylength(plaintext)-1 do
      begin
        result:=encode(PlainText[iter],inttostr(iter),result);
      end;
      for iter:=0 to getarraylength(plaintext)-1 do
      begin
        result:=encode(inttostr(iter),CipherText[iter],result);
      end;

    end;

    begin
      writeln(encodeall('bad'));
    end.

    Theres a more efficient way to combine them, but I'm lazy.

    Now what I mean by 3 arrays, is before I had 1 for loop, with PlainText To CipherText. However, bad would be ada. This is how it would go

    bad -a to c
    bcd -b to d
    dcd -now there are 2 d's, one has already been converted, one has not, so c to b
    dbd -d to a
    aba

    So first I needed to but a placeholder in there, the middle array. So I used the numbers from the indexes of the arrays. Unfortunately this won't work if the string contains numbers.

    To solve that, you will have to do it so that it replaces from the original string, and puts all the new parts (36 of them) together after. Instead of how it is now, changing the string as you go along. Read from OldString the position of all the plaintext a's. Then put the ciphertext of A into NewString in the same positions. Read from OldString, write NewString. Reading and writing on the same thing causes problems because you don't know what has already been converted and what hasn't.

    This wouldn't be a problem if you were converting letters to shapes and symbols, but letters to other letters is more complicated.

  6. #6
    Join Date
    Jun 2006
    Posts
    89
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    sweet, thanks, i know this isnt the first time you've answered a question for me

  7. #7
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Hehe it's what I do

    Don't forget to finish PlainText:=['a','b','c','d'] I'm too lazy lol

  8. #8
    Join Date
    Jun 2006
    Posts
    89
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    there is a problem...

    final code:
    Code:
     program New;
    {.include SRL/SRL.scar}
    function encode(a,b:string;str:String):String;
    var
    i:integer;
    strdone:String;
    begin
    for i:=1 to Length(str) do
    begin
    if(str[i]=a)then    //the letter being replaced
    strdone:=strdone+b; //the letter you want to replace it as
    if(not(str[i]=a))then
    strdone:=strdone+str[i];
    end;
    result:=strdone;
    end;
    
    function encodeall(WhatToEncode:string):string;
    var
      PlainText,CipherText:array of string;
      iter:integer;
    begin
      PlainText:=['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','1','2','3','4','5','6','7','8','9','0']
      CipherText:=['z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a','0','9','8','7','6','5','4','3','2','1']
      result:=WhatToEncode;
      for iter:=0 to getarraylength(plaintext)-1 do
      begin
        result:=encode(PlainText[iter],inttostr(iter),result);
      end;
      for iter:=0 to getarraylength(plaintext)-1 do
      begin
        result:=encode(inttostr(iter),CipherText[iter],result);
      end;
    
    end;
    
    begin
      writeln(encodeall('Hello'));
    end.
    what it writes: Hxwvxwxwyxwxwyxwxwyxwxwyxwxwyxwv
    should be something a little shorter...

  9. #9
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Now that I think about it, it's better to go by character than letter. Go thru with str[i] and change it to the corresponding character from the crypttext, I'll write it later if you don't know what I mean.

  10. #10
    Join Date
    Jun 2006
    Posts
    89
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ya, i really didnt get that, wasnt to clear on what you said

  11. #11
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    SCAR Code:
    function encodeall(WhatToEncode:string):string;
    var
      PlainText,CipherText:array of string;
      iter,i:integer;
      theboolean:boolean;
    begin
      PlainText:=['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','1','2','3','4','5','6','7','8','9','0']
      CipherText:=['z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a','0','9','8','7','6','5','4','3','2','1']
      for i:=1 to Length(WhatToEncode) do
      begin
        iter:=0;
        theboolean:=false;
        repeat
          if WhatToEncode[i]=PlainText[iter] then
          begin
            theboolean:=true;
            result:=result+CipherText[iter]
          end;
          iter:=iter+1;
        until ((theboolean) or (iter=getarraylength(plaintext)));
      end;
    end;
    that should do it

    The for loop goes through each character of the string. Then for each character of the string it goes through the array to find which letter it is, and adds the corresponding cipher letter to the result. This way it knows what has been converted already.


    btw add ' ' in the same position in the arrays if you want to keep the word spacing, or in random places to not.


    edit: better version, I'm done now
    SCAR Code:
    function Cipher(WhatToEncode,EncodeOrDecode:string):string;
    var
      PlainText,CipherText:array of string;
      iter,i:integer;
      theboolean:boolean;
    begin
      case lowecase(EncodeOrDecode) of
        'encode': begin
          CipherText:=[' ','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','1','2','3','4','5','6','7','8','9','0']
          PlainText:=['z','y','x','w','v','u','t','s','r',' ','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a','0','9','8','7','6','5','4','3','2','1']
         end;
        'decode': begin
          PlainText:=[' ','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','1','2','3','4','5','6','7','8','9','0']
          CipherText:=['z','y','x','w','v','u','t','s','r',' ','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a','0','9','8','7','6','5','4','3','2','1']
         end;
      end;
      for i:=1 to Length(WhatToEncode) do
      begin
        iter:=0;
        theboolean:=false;
        repeat
          if WhatToEncode[i]=PlainText[iter] then
          begin
            theboolean:=true;
            result:=result+CipherText[iter]
          end;
          iter:=iter+1;
        until ((theboolean) or (iter=getarraylength(plaintext)));
      end;
    end;

    begin
    writeln(Cipher('fsrgirgizigvxhvfinvggztv','Decode'));
    end.

  12. #12
    Join Date
    Jun 2006
    Posts
    89
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    lol, ok, thanks a ton for that, extremley helpful

  13. #13
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Np it was fun

  14. #14
    Join Date
    Feb 2007
    Posts
    215
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Looking for encryption, eh? Fun stuff My first encryption algorithm was crap (i didnt know alot about scar back then, or arrays. I had a very long case statement hehe

    It has a form too. And the semicolons i forgot to add while i was making the case so i added em in afterwards (just pressed semicolon, down arrow, etc.) so they kinda go in waves lol.

    I dont suggest you pick up on my horrible coding style. I cant believe how crappy this is.

    SCAR Code:
    {+++++++++++++++++++++The N-Kryptor++++++++++++++++++++++++++++}
    //1. run the script
    //2. type in what is to be encrypted
    //3. press the "N-Krypt!" button
    //4. the encrypted message will appear in the debug box
    //NOTE: the N-Kryptor is not capital letter capable, "`" and "~"
    // are not valid characters unless using the decryptor. the
    //N-Kryptor will not decrypt messages encrypted by other programs
    {++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}





    program N_Kryptor;
    var
      form: TForm;
      Application: TApplication;
      MessageToEncrypt: TLabel;
      MessageTxt: string;
      txtMessage: TMemo;
      ButtonOK,Btn_Cancel: TButton;
      encryptordecrypt: TComboBox;
      encrypt:boolean;

    procedure buttonclick(sender: TObject);
    begin
    MessageTxt :=txtMessage.text
    encrypt:=true
    if(not(encryptordecrypt.Text='Encrypt'))then
    begin
    encrypt:=false
    end
    end;




    procedure Go(text:string);
    var encrypto,txt,k:string;

    begin
    repeat
    k:=strget(text,1);
    if(encrypt=true)then
    begin
    case k of
    'q':txt:='`';
    'w':txt:='X';
    'e':txt:='K' ;
    'r':txt:='}'  ;
    't':txt:='{'   ;
    'y':txt:='?'    ;
    'u':txt:='>'     ;
    'i':txt:='<'      ;
    'o':txt:='"'       ;
    'p':txt:=':'        ;
    'a':txt:='+'         ;
    's':txt:='_'          ;
    'd':txt:=')'           ;
    'f':txt:='('            ;
    'g':txt:='*';
    'h':txt:='&' ;
    'j':txt:='^'  ;
    'k':txt:='%'   ;
    'l':txt:='$'    ;
    'z':txt:='#'     ;
    'x':txt:='@'      ;
    'c':txt:='!'       ;
    'v':txt:='1'        ;
    'b':txt:='2'         ;
    'n':txt:='3'          ;
    'm':txt:='4'           ;
    '1':txt:='5'            ;
    '2':txt:='6'             ;
    '3':txt:='7'              ;
    '4':txt:='8'               ;
    '5':txt:='9'                ;
    '6':txt:='0'                 ;
    '7':txt:='/'                  ;
    '8':txt:='.'                   ;
    '9':txt:=','                    ;
    '0':txt:='m'                     ;
    ',':txt:='n'                      ;
    '.':txt:='b'                        ;
    '/':txt:='v'                       ;
    ';':txt:='c'                         ;
    '[':txt:='x'                          ;
    ']':txt:='z'                           ;
    '\':txt:=';'                            ;
    '-':txt:='l'                             ;
    '=':txt:='k'                              ;
    '!':txt:='j'                               ;
    '@':txt:='h'                                ;
    '#':txt:='g'                                 ;
    '$':txt:='f'                                  ;
    '%':txt:='d'                                   ;
    '^':txt:='s'                                    ;
    '&':txt:='a'                                     ;
    '*':txt:='\'                                      ;
    '(':txt:=']'                                       ;
    ')':txt:='['                                        ;
    '_':txt:='p'                                         ;
    '+':txt:='o'                                          ;
    '<':txt:='i'                                           ;
    '>':txt:='u'                                            ;
    '?':txt:='y'                                             ;
    '|':txt:='t'                                              ;
    '{':txt:='r'                                               ;
    '}':txt:='e'                                                ;
    ':':txt:='w'                                                 ;
    '"':txt:='q'                                                  ;
    ' ':txt:='~'
    end;
    end;
    if(encrypt=false)then
    begin
    case k of
    '`':txt:='q';
    'X':txt:='w';
    'K':txt:='e' ;
    '}':txt:='r'  ;
    '{':txt:='t'   ;
    '?':txt:='y'    ;
    '>':txt:='u'     ;
    '<':txt:='i'      ;
    '"':txt:='o'       ;
    ':':txt:='p'        ;
    '+':txt:='a'         ;
    '_':txt:='s'          ;
    ')':txt:='d'           ;
    '(':txt:='f'            ;
    '*':txt:='g';
    '&':txt:='h' ;
    '^':txt:='j'  ;
    '%':txt:='k'   ;
    '$':txt:='l'    ;
    '#':txt:='z'     ;
    '@':txt:='x'      ;
    '!':txt:='c'       ;
    '1':txt:='v'        ;
    '2':txt:='b'         ;
    '3':txt:='n'          ;
    '4':txt:='m'           ;
    '5':txt:='1'            ;
    '6':txt:='2'             ;
    '7':txt:='3'              ;
    '8':txt:='4'               ;
    '9':txt:='5'                ;
    '0':txt:='6'                 ;
    '/':txt:='7'                  ;
    '.':txt:='8'                   ;
    ',':txt:='9'                    ;
    'm':txt:='0'                     ;
    'n':txt:=','                      ;
    'b':txt:='.'                        ;
    'v':txt:='/'                       ;
    'c':txt:=';'                         ;
    'x':txt:='['                          ;
    'z':txt:=']'                           ;
    ';':txt:='\'                            ;
    'l':txt:='-'                             ;
    'k':txt:='='                              ;
    'j':txt:='!'                               ;
    'h':txt:='@'                                ;
    'g':txt:='#'                                 ;
    'f':txt:='$'                                  ;
    'd':txt:='%'                                   ;
    's':txt:='^'                                    ;
    'a':txt:='&'                                     ;
    '\':txt:='*'                                      ;
    ']':txt:='('                                       ;
    '[':txt:=')'                                        ;
    'p':txt:='_'                                         ;
    'o':txt:='+'                                          ;
    'i':txt:='<'                                           ;
    'u':txt:='>'                                            ;
    'y':txt:='?'                                             ;
    't':txt:='|'                                              ;
    'r':txt:='{'                                               ;
    'e':txt:='}'                                                ;
    'w':txt:=':'                                                 ;
    'q':txt:='"'                                                  ;
    '~':txt:=' ';
    '§':txt:='';
    '¿':txt:='';

    end;
    end;
    insert(txt,encrypto,length(encrypto)+1)
    delete(text,1,1)
    until(length(text)=0)

    if(encrypt=true)then
    begin
    writeln('¿'+encrypto+'§')
    end;
    if(encrypt=false)then
    begin
    writeln(encrypto)
    end;
    end;{
      +----------+
     /form stuff/-------------------------------------
    +---------+
    }
    begin

          form:= TForm.Create(Application);
      Form.Width := 700;
      Form.Height := 500;
      Form.Position := poScreenCenter;
      Form.BorderStyle := bsDialog;
      Form.Caption := 'The N-Kryptor V1.03';

      //Create things on form
      MessageToEncrypt := TLabel.Create(Form);
      MessageToEncrypt.Top := 24;
      MessageToEncrypt.Left := 16;
      MessageToEncrypt.Caption := 'Message to be encrypted/decrypted:';
      MessageToEncrypt.Parent := Form;
      txtMessage := TMemo.Create(Form);
      txtMessage.Top := 40;
      txtMessage.Left := 86;
      txtMessage.Width := 500;

       encryptordecrypt                  := TComboBox.Create(Form);
       encryptordecrypt.Top              := 200;
       encryptordecrypt.Left             := 20;
       encryptordecrypt.Width            := 100;
       encryptordecrypt.Parent           := Form;
       encryptordecrypt.DropDownCount    := 3;
       encryptordecrypt.Items.Add        ('Encrypt');
       encryptordecrypt.Items.Add        ('Decrypt');
       encryptordecrypt.ItemIndex        := 0;

      txtMessage.Parent := Form;
        ButtonOK := TButton.Create(Form);
      ButtonOK.Left := 100;
      ButtonOK.Top := 300;
      ButtonOK.Width := 450;
      ButtonOK.Height := 100;
      ButtonOK.Caption := 'Run N-Kryptor';
      ButtonOK.Font.Height := -60
      ButtonOK.Font.Name := 'Verdana';
      ButtonOK.OnClick := @buttonclick;
      ButtonOK.Parent := Form;
      ButtonOK.Default := True;
      ButtonOK.ModalResult:= mrOk;

     Btn_Cancel :=Tbutton.Create(Form);
     Btn_Cancel.left :=675;
     Btn_Cancel.top := 490;
     Btn_Cancel.Height :=10;
     Btn_Cancel.width :=25;
     Btn_Cancel.Parent :=Form;
     Btn_Cancel.ModalResult
     Form.ShowModal;
      Form.Free;
     Go(MessageTxt)

     end.

  15. #15
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    what's with the funky semicolons up at the top?
    Interested in C# and Electrical Engineering? This might interest you.

  16. #16
    Join Date
    Feb 2007
    Posts
    215
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Smartzkid View Post
    what's with the funky semicolons up at the top?
    taken from my post...
    And the semicolons i forgot to add while i was making the case so i added em in afterwards (just pressed semicolon, down arrow, etc.) so they kinda go in waves lol.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Abstract Photo Manipulation
    By Torrent of Flame in forum Graphics and Multimedia
    Replies: 17
    Last Post: 03-02-2009, 07:13 PM
  2. Quick Tut on Debug Box manipulation
    By n3ss3s in forum OSR Advanced Scripting Tutorials
    Replies: 11
    Last Post: 09-16-2008, 01:31 AM
  3. functions w/ bit manipulation
    By sherlockmeister in forum Research & Development Lounge
    Replies: 9
    Last Post: 04-06-2008, 06:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •