Data
String Manipulation
Objective: Perform string operations such as concatenation and substring extraction.
- Concatenate strings:
str add "Hello" " " "World" greeting;
- "Hello", " ", "World" are the strings to concatenate.
- "greeting" is the new variable for the result.
- Extract a substring:
str cut "0" "5" greeting substring;
- "0" is the starting index.
- "5" is the ending index.
- "greeting" is the source string.
- "substring" is the new variable for the result.
- Display the substring:
csl write substring;
Mathematical Operations
Objective: Perform basic arithmetic operations like addition and multiplication.
- Add numbers:
mat plus "1" "2" "3" sum;
- "1", "2", "3" are the numbers to add.
- "sum" is the new variable for the result.
- Multiply numbers:
mat mult "2" "3" "4" product;
- "2", "3", "4" are the numbers to multiply.
- "product" is the new variable for the result.
- Display the results:
csl write sum; csl write product;
Practical Example
Objective: Create a full name and calculate a total price.
- Create a full name:
str add "John" " " "Doe" fullName;
- Extract the first name:
str cut "0" "4" fullName firstName; csl write firstName;
- Calculate total price:
mat mult "10" "2" total; csl write total;
Tips
- Ensure numbers are passed as strings in math operations.
- Use
str eqs
for string comparisons. - Apply
crt
commands for secure data handling.
Conclusion
Data manipulation commands in Virtel Steps, such as str add
, mat plus
, and bln and
, provide essential tools for processing and transforming data.
Commands
Extracts a substring from a string between specified positions and stores it in a new variable.
first
: The starting index (inclusive) (type: VAR).last
: The ending index (exclusive) (type: VAR).value
: The string to extract from (type: VAR).newVarName
: The name of the new variable for the substring (type: VAR).
This example extracts "Hello" from "Hello World" and prints it.
Concatenates multiple strings into one and stores the result in a new variable.
firstStr, secondStr, ..., lastStr
: The strings to concatenate (type: VAR).newVarName
: The name of the new variable for the result (type: VAR).
This example concatenates "Hello", " ", and "World" into "Hello World" and prints it.
Gets the length of a string and stores it in a new variable.
value
: The string to measure (type: VAR).newVarName
: The name of the new variable for the length (type: VAR).
This example gets the length of "Hello" ("5") and prints it.
Gets a character at a specific index in a string and stores it in a new variable.
index
: The index of the character (type: VAR).value
: The string to extract from (type: VAR).newVarName
: The name of the new variable for the character (type: VAR).
This example gets "H" from "Hello" and prints it.
Checks if two strings are equal and stores the result ("true" or "false") in a new variable.
first
: The first string to compare (type: VAR).second
: The second string to compare (type: VAR).newVarName
: The name of the new variable for the result (type: VAR).
This example checks if "Hello" equals "Hello" and prints "true".
Splits a string by a regex pattern and stores the resulting parts in a new list.
regex
: The regex pattern to split by (type: VAR).value
: The string to split (type: VAR).newVarListName
: The name of the new list for the parts (type: LIST).
This example splits "a,b,c" by "," into a list and prints "a".
Adds multiple numbers and stores the sum in a new variable.
a, b, ..., lastNum
: The numbers to add (type: VAR).newVarName
: The name of the new variable for the sum (type: VAR).
This example adds 1, 2, and 3, storing "6" in "sum" and printing it.
Subtracts numbers from the first one and stores the result in a new variable.
a
: The initial number (type: VAR).b, ..., lastNum
: The numbers to subtract (type: VAR).newVarName
: The name of the new variable for the result (type: VAR).
This example subtracts 2 and 3 from 10, storing "5" in "result" and printing it.
Multiplies multiple numbers and stores the product in a new variable.
a, b, ..., lastNum
: The numbers to multiply (type: VAR).newVarName
: The name of the new variable for the product (type: VAR).
This example multiplies 2, 3, and 4, storing "24" in "product" and printing it.
Divides the first number by subsequent numbers and stores the result in a new variable.
a
: The initial number (type: VAR).b, ..., lastNum
: The divisors (type: VAR).newVarName
: The name of the new variable for the result (type: VAR).
This example divides 100 by 2 and then by 5, storing "10" in "result" and printing it.
Checks if two numbers are equal.
a
: The first number.b
: The second number.newVarName
: The new variable to store the result (boolean as a string).
This example checks if the numbers 5 and 5 are equal, and stores the result in the isEqual
variable, which will be "true".
Checks if the first number is greater than the second number.
a
: The first number.b
: The second number.newVarName
: The new variable to store the result (boolean as a string).
This example checks if 10 is greater than 5, and stores the result in the isGreater
variable, which will be "true".
Checks if the first number is less than the second number.
a
: The first number.b
: The second number.newVarName
: The new variable to store the result (boolean as a string).
This example checks if 5 is less than 10, and stores the result in the isLess
variable, which will be "true".
Checks if the first number is greater than or equal to the second number.
a
: The first number.b
: The second number.newVarName
: The new variable to store the result (boolean as a string).
This example checks if 10 is greater than or equal to 5, and stores the result in the isGreaterOrEqual
variable, which will be "true".
Checks if the first number is less than or equal to the second number.
a
: The first number.b
: The second number.newVarName
: The new variable to store the result (boolean as a string).
This example checks if 5 is less than or equal to 10, and stores the result in the isLessOrEqual
variable, which will be "true".
Generates a random number within a given range.
min
: The minimum value.max
: The maximum value.newVarName
: The new variable to store the result.
This example generates a random number between 1 and 10 and prints it to the console.
Converts a floating-point number to an integer.
numberDouble
: The floating-point number.newVarName
: The new variable to store the result.
This example converts 5.9 to 5 and stores the result in the result
variable.
Performs a logical "NOT" operation on a boolean value and stores the result in a new variable.
a
: The boolean value to negate ("true" or "false") (type: VAR).newVarName
: The name of the new variable to store the result (type: VAR).
This example negates "true" to "false" and prints the result.
Performs a logical "AND" operation on two boolean values and stores the result in a new variable.
a
: The first boolean value ("true" or "false") (type: VAR).b
: The second boolean value ("true" or "false") (type: VAR).newVarName
: The name of the new variable to store the result (type: VAR).
This example performs "true AND false", storing "false" in "result" and printing it.
Performs a logical "OR" operation on two boolean values and stores the result in a new variable.
a
: The first boolean value ("true" or "false") (type: VAR).b
: The second boolean value ("true" or "false") (type: VAR).newVarName
: The name of the new variable to store the result (type: VAR).
This example performs "true OR false", storing "true" in "result" and printing it.
Performs a logical "XOR" operation on two boolean values and stores the result in a new variable.
a
: The first boolean value ("true" or "false") (type: VAR).b
: The second boolean value ("true" or "false") (type: VAR).newVarName
: The name of the new variable to store the result (type: VAR).
This example performs "true XOR true", storing "false" in "result" and printing it.
Encrypts text using AES with a specified key and stores the encrypted result in a new variable.
text
: The text to encrypt (type: VAR).key
: The encryption key (type: VAR).newVarName
: The name of the new variable to store the encrypted text (type: VAR).
This example encrypts "Secret message" with "myKey123" and prints the encrypted result.
Decrypts AES-encrypted text using a specified key and stores the decrypted result in a new variable.
text
: The encrypted text to decrypt (type: VAR).key
: The decryption key (type: VAR).newVarName
: The name of the new variable to store the decrypted text (type: VAR).
This example encrypts "Secret message", decrypts it with the same key, and prints "Secret message".
Encodes text into Base64 and stores the result in a new variable.
text
: The text to encode (type: VAR).newVarName
: The name of the new variable to store the Base64-encoded text (type: VAR).
This example encodes "Hello" into "SGVsbG8=" and prints it.
Decodes Base64-encoded text and stores the result in a new variable.
text
: The Base64-encoded text to decode (type: VAR).newVarName
: The name of the new variable to store the decoded text (type: VAR).
This example encodes "Hello" to Base64, decodes it back, and prints "Hello".
Creates an HMAC (hash-based message authentication code) for text using a key and stores it in a new variable.
text
: The text to create an HMAC for (type: VAR).key
: The key for HMAC generation (type: VAR).newVarName
: The name of the new variable to store the HMAC (type: VAR).
This example generates an HMAC for "Message" with "secretKey" and prints it.
Verifies an HMAC for text using a key and stores the result ("true" or "false") in a new variable.
text
: The original text (type: VAR).mac
: The HMAC to verify (type: VAR).key
: The key used for HMAC generation (type: VAR).newVarName
: The name of the new variable to store the verification result (type: VAR).
This example generates an HMAC and verifies it, printing "true" if valid.
Generates a key pair for KEM (Key Encapsulation Mechanism) and stores the public and private keys in new variables.
publicNewVarName
: The name of the variable to store the public key (type: VAR).privateNewVarName
: The name of the variable to store the private key (type: VAR).
This example generates a KEM key pair and prints the public key.
Encapsulates a shared key using KEM with a public key, storing the ciphertext and shared key in new variables.
publicKey
: The public key for encapsulation (type: VAR).ciphertextNewVarName
: The name of the variable to store the ciphertext (type: VAR).sharedKeyNewVarName
: The name of the variable to store the shared key (type: VAR).
This example encapsulates a shared key with a public key and prints the shared key.
Decapsulates a shared key using KEM with a private key and ciphertext, storing the shared key in a new variable.
ciphertext
: The ciphertext to decapsulate (type: VAR).privateKey
: The private key for decapsulation (type: VAR).sharedKeyNewVarName
: The name of the variable to store the shared key (type: VAR).
This example generates a key pair, encapsulates a key, decapsulates it, and prints the shared key.
Generates a key pair for DSA (Digital Signature Algorithm) and stores the public and private keys in new variables.
publicNewVarName
: The name of the variable to store the public key (type: VAR).privateNewVarName
: The name of the variable to store the private key (type: VAR).
This example generates a DSA key pair and prints the public key.
Signs a message using DSA with public and private keys, storing the signature in a new variable.
message
: The message to sign (type: VAR).publicKey
: The public key (type: VAR).privateKey
: The private key (type: VAR).signatureNewVarName
: The name of the variable to store the signature (type: VAR).
This example signs "Hello" with DSA keys and prints the signature.
Verifies a DSA signature for a message using a public key, storing the result ("true" or "false") in a new variable.
message
: The original message (type: VAR).signature
: The signature to verify (type: VAR).publicKey
: The public key (type: VAR).newVarName
: The name of the variable to store the verification result (type: VAR).
This example signs "Hello", verifies the signature, and prints "true" if valid.
Computes the SHA-256 hash of text and stores it in a new variable.
text
: The text to hash (type: VAR).newVarName
: The name of the variable to store the hash (type: VAR).
This example computes the SHA-256 hash of "Hello" and prints it (e.g., "a591a6d40bf...").
Computes the SHA-512 hash of text and stores it in a new variable.
text
: The text to hash (type: VAR).newVarName
: The name of the variable to store the hash (type: VAR).
This example computes the SHA-512 hash of "Hello" and prints it.
Creates a JWT (JSON Web Token) from a payload and secret, storing it in a new variable.
payload
: The data for the token (type: VAR).secret
: The secret key for signing (type: VAR).newVarName
: The name of the variable to store the JWT (type: VAR).
This example creates a JWT with payload "user:john" and prints it.
Verifies a JWT with a secret key and stores the result ("true" or "false") in a new variable.
token
: The JWT to verify (type: VAR).secret
: The secret key used for signing (type: VAR).newVarName
: The name of the variable to store the verification result (type: VAR).
This example creates a JWT, verifies it, and prints "true" if valid.