Showing posts with label Encryption. Show all posts
Showing posts with label Encryption. Show all posts

Friday, June 7, 2013

How to convert plain text into hexadecimal and octal formats in Loadrunner?

I already have explained how to use web_convert_param function. In this post I will write about how to convert plain test to hexadecimal format. I once used this for encoding a string.

char *PlaintoHexadecimal(const char *InputS, char *OutputS)
{   

                int i;
                char CurrentChar;
                char CurrentStr[4] = {0};   
               
                OutputS[0] = '\0'; 
                for (i = 0; CurrentChar = InputS[i]; i++)  
                {
                                sprintf(CurrentStr, "%X", CurrentChar);          
                                strcat(OutputS, CurrentStr);   
               
                } 
            return OutputS;
               
}


Action()
{
   
char InputS[] = "This is plain string";
char OutputS[100];


lr_output_message("The input is %s",InputS);
lr_output_message("The output is %s", PlaintoHexadecimal(InputS, OutputS));

return 0;

}

Once you execute the above code, the string will be converted to hexadecimal format as shown below:




Wow Done!!!! Now how to convert the plain text in octal format?
Just change the X factor to o factor ;). I am not kidding. You just have to change the below string

sprintf(CurrentStr, "%X", CurrentChar);        to     sprintf(CurrentStr, "%o", CurrentChar);          

Hope you will execute that and see what happens. I got this:




Thank you so much for reading and following.

How to convert plain text into URL format in Loadrunner?

Sometimes while parametrization and correlation we need to put a check on the type of value that is being passed. And we need to convert the format of the variable. For this we have a function in LoadRunner web_convert_param this function either converts HTML text to plain text or URL, or converts plain text to URL.

The syntax of web_convert_param is as:

int web_convert_param( const char *ParamName, [char *SourceString] char *SourceEncoding, char *TargetEncoding, LAST );
In the below example we are converting string "Plain text to be converted to URL" to URL format from plain format.

Example:

Action()
{

char param1[]="Plain text to be converted to URL";

lr_save_string(param1, "Input");

lr_output_message("The value of input is : %s",lr_eval_string("{Input}"));
web_convert_param("Input","SourceEncoding=PLAIN","TargetEncoding=URL", LAST );

lr_output_message("The value after converting is : %s",lr_eval_string("{Input}"));
return 0;

}

The output will be as :

 The following table shows same content in the three formats :
HTML
URL
Plain Text
<mytag>&
%3Cmytag%3E%26
<mytag>&

That’s all for today :). Thanks for reading guys!!!

How to encrypt a string in Loadrunner using password encoder? How to use the encrypted value in script?

Suppose you face a situation, when you want to encrypt your password and use this value in script. This is a cake walk.

You have to go to password encoder, the Password Encoder tool lets you enter regular text and convert it to an encoded string.

Choose Start > Programs > LoadRunner > Tools >Password Encoder to open the Password Encoder tool.



Password: Enter the password you want to encode, and then click Generate.
Encoded string: Displays the encoded password string.
Generate: Generates an encoded string after a password is entered.
Copy: Copies the encoded password string to the clipboard.

Done!!!

Now, How to use the encrypted value in script?

This is done by using lr_decrypt function as shown below in script.

vuser_init()
{
    web_set_proxy("oregon:8080");
    web_set_user("oregon_user",

    lr_decrypt("518a296870b8b8d477e2f63cbbe5f2a0")," oregon:8080");
    web_url("web_url",
        "URL=http:// oregoncity.com /",
        "TargetFrame=",
        "Resource=0",
        "Referer=",
        LAST );

}