Skip to content

New General Functions

Irtsa edited this page Jan 3, 2025 · 5 revisions

General Functions

These functions do not extend from any of the current object/class from greyscript. Instead, these functions are similar to the System Functions or "built-in" functions.

The following are a list of new functions that can be utilized.





factors (value)

Will return a list of the factors of said number.

print(factors(20))
-- [1, 2, 4, 5, 10, 20]


factorsPrime (value)

Will return a list of the prime factors of the said number.

print(factorsPrime(20))
-- [2, 2, 5]


isPrime (value)

Will return true if said number is prime, false if otherwise (1 or 0).

print(isPrime(7))
-- 1(true)


greatestCommonFactor (Values)

Will return the greatest common factor of the given Values.

print(greatestCommonFactor([10, 20, 55])
-- 5


decimalpercent (value)

Will convert the number value into percentage form assuming the value is a decimal.

print(decimalpercent(10))
-- 1000


percentdecimal (value)

Will convert the number value into decimal form assuming the value is a percentage.

print(percentdecimal(10))
-- 0.1


percentmultiplier (value)

Will convert the number value into multiplier form assuming the value is a percentage.

print(percentmultiplier(10))
-- 1.1


multiplierpercent (value)

Will convert the number value into percentage form assuming the value is a multiplier.

print(multiplierpercent(10))
-- 900


decimalfraction (value)

Will convert the number value into fraction form assuming the value is a decimal.

print(decimalfraction (10))
-- "61/200"


baseToDecimal (value, base)

Will convert the number value variable assuming base 10 into given base base and will return as list.

print(baseConvert(100, 7))
-- [2, 0, 2]


decimalToBase (value, base)

Will convert the number value variable into base 10 from given base and will return as number.

print(baseToDecimal("4d2", 16))
-- 1234


hex (value)

Will return the number value variable assuming number is base 10 as a hexidecimal string.

print(hex(100))
-- "64"


bin (value)

Will return the number value variable assuming number is base 10 as a binary string.

print(bin(100))
-- "1100100"


oct (value)

Will return the number value variable assuming number is base 10 as a octal string.

print(oct(100))
-- "144"


all (value)

Will return true if all values in given list Values are true.

print(all([true, true, false])
-- 0(false)


any (value)

Will return true if at least one values in given list Values are true.

print(any([true, true, false])
-- 1(true)


foldercount (folder)

Will return how many folders are in the given folder folder, will return null if folder is not of type file(folder).

folder = get_shell.host_computer.File("/home")
print(foldercount(folder))
-- 3


filecount (folder)

Will return how many files are in the given folder folder, will return null if folder is not of type file(folder).

folder = get_shell.host_computer.File("/etc")
print(filecount(folder))
-- 3


open_ports (router)

Will return a list of open used ports on the given router router.

print(open_ports(get_router))
-- [port, port, port, port]


closed_ports (router)

Will return a list of closed used ports on the given router router.

print(closed_ports(get_router))
-- [port, port]


filehash (file)

Will return the md5 hash of the file contents of the given file file.

print(filehash(get_shell.host_computer.File("/etc/passwd")))
-- returns "e2d0144aa03278f03fb1d50c1c46b7ca"


folderhash (folder)

Will return the md5 hash of all child folder and file paths concatenated of the given folder folder.

print(folderhash(get_shell.host_computer.File("/home")))
-- returns "9c746492c2295b799aa637d641b3998a"


nlog(number)

Will return the natural log of the provided number number.

print(nlog(100))
-- returns 4.62607


log10(number)

Will return the log with the base of 10 of the provided number number.

print(log10(100))
-- returns 2


e

Will return Euler's number.

print(e)
-- returns 2.718281828459045


rndint(min, max)

Will return a random whole number between the provided min and max values inclusive.

print(rndint(0, 2))
-- returns 1


rnduni(min, max, decimals)

Will return a random decimal number between the provided min and max values inclusive, rounded to the given decimal decimal places.

print(rndint(0, 2, 4))
-- returns 1.3455