added handling of key length in base conversion