jmeterjmeter-pluginsjmeter-5.0

Converting base 16 value to base 62 using Jmeter script


I want to convert base 16 value to base 62 value and this value to be used in jmeter script execution.

I have a scenario where I have to fetch UID_Hex from DB and convert it into base 62 value and use it in further script execution.

How to convert base 16 to base 62 value?


Solution

  • You can do it using a suitable JSR223 Test Element and Groovy language

    Example code:

    static def base16ToBase10(String base16) {
        def result = new BigInteger('0')
        def chars = "0123456789ABCDEF"
    
        base16.each { c ->
            result = result * 16 + chars.indexOf(c.toUpperCase())
        }
    
        result
    }
    
    static def base10ToBase62(BigInteger base10) {
        def chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
        def result = ''
    
        while (base10 > 0) {
            def remainder = base10.mod(62)
            result = chars[remainder.intValue()] + result
            base10 = base10.divide(62 as BigInteger)
        }
    
        result
    }
    
    def UID_Hex = 'C8ED6D6046D34807BC5F0EBF065072EC'
    
    
    def TO_Converted_Value = base10ToBase62(base16ToBase10(UID_Hex))
    
    //do what you need with the converted value here
    

    Demo:

    enter image description here