- Stephen Stills, Rick Curtis and Michael Curtis
#===================================================================================================
# Example Script: Aztec Primitive Classes Script
# Demonstrates use of Aztec primitive classes, primitive class framework, and primitive references.
#===================================================================================================
# Simple enumeration for use below to demo enum methods.
enum SingleDigits { zero, one, two, three, four, five, six, seven, eight, nine }
# Main run-time entry point for the script.
method Main
{
data<int> Count
data<int> IntTest
data<int> RandomInt
data<int> TotalResult
data<int> InternalKey = 113
data<string> EnumName
data<string> TotalString
data<string> EncryptedString
data<string ref> StringRef
data<SingleDigits> DigitEnum
#------------------------------------------------------------------------------------
# Get a random integer between 0 and 255 and analyze the bit settings. We will also
# manually build back up the same number based on bit settings - as demonstration.
#------------------------------------------------------------------------------------
RandomInt = int.Random(0,255)
iterate ( Count in 1..8 )
{
# If bit is on, add contribution from this term to result total (2**(n-1)).
if ( RandomInt.BitTest(Count) )
{
TotalResult.Add(2 ** (Count - 1))
}
}
StdIO.Write("Original random integer is " + RandomInt.Str())
StdIO.Write("Same number built up by bit analysis is " + TotalResult.Str())
StdIO.Write("Bit pattern for original random number is " + RandomInt.Str("B8"))
# Loop through several of the enumeration values and work with them using primitive methods.
for ( Count = 1 ; Count <= 4 ; Count.Inc() )
{
EnumName = SingleDigits.Enum(Count).Str()
StdIO.Write("SingleDigits name for index " + Count.Str() + " is '" + EnumName + "'")
# Use the name from the enum Str() method to get the enumeration back.
DigitEnum = SingleDigits.Enum(EnumName)
StdIO.Write("SingleDigits name (index to name to enum) is '" + DigitEnum.Str() + "'")
}
# Build up a string using random characters and then pad it to be a specific size.
iterate ( Count in 1..25 )
{
# Get random character from 65 - 90 (upper case letters) and add it to string.
TotalString.Add(IntChar(65 + int.Random(0,25)))
}
StdIO.Write("Padded string is '" + TotalString.Pad(45,'-',string.PadCenter) + "'")
# Encrypt the padded string and then decrypt it to get the original back.
EncryptedString = TotalString.Encrypt(InternalKey)
StdIO.Write("Encrypted string is '" + EncryptedString + "'")
StdIO.Write("Decrypted string is '" + EncryptedString.Decrypt(InternalKey) + "'")
# Get the reference of a string, then modify and display it via ref and from original.
@StringRef = @EncryptedString
StdIO.Write("Same decrypted string via ref is '" + StringRef + "'")
StdIO.Write("Same string to lower case via ref is '" + StringRef.Lwr() + "'")
StdIO.Write("Original string is changed to '" + EncryptedString + "'")
# Modify an integer by passing reference to method and it gets doubled.
IntTest = 100
StdIO.Write("Original integer is " + IntTest.Str())
DoubleInt(@IntTest)
StdIO.Write("Integer is now " + IntTest.Str() + " after being doubled via method")
}
# Method takes an integer reference and doubles the value of the referenced integer object.
method DoubleInt(int ref IntRefArg)
{
# Double the integer we're referencing.
IntRefArg.Mult(2)
}