Retrieve item from record using a variable

Still getting familiar with AS, trying to make something where you type in a string and it spits out another based off of a code.

display dialog "string to encode" default answer ""
set stringtoencode to text returned of result

set encoded to {}
set code to {a:"b", b:"c", c:"a"}

repeat with i from 1 to (count characters of stringtoencode)
	set end of encoded to ((character i of stringtoencode) of code)
end repeat

display dialog encoded as text

Keeps giving me “Can’t get stringtoencode of {a:“b”, b:“c”, c:“a”}.” and I’m assuming it’s because I can’t retrieve an item from a record using a variable. Is this why I’m having a problem? Is there a (simple) way to fix this?

character i of string to encode is text, not a variable. You shouldn’t really be using a record at all for this.

Perhaps something simpler:

display dialog "string to encode" default answer ""
set stringtoencode to text returned of result --> qwerty

set encoded to {}
set alph to "abcdefghijklmnopqurtuvwxyz" -- add caps if you like
set code to "bcdefghijklmnopqurtuvwxyza"

repeat with i from 1 to (count characters of stringtoencode)
	set Char to character i in stringtoencode
	set Off to offset of Char in alph
	set end of encoded to character Off of code
end repeat

display dialog encoded as text --> "uxftuz"