What should be changed in scheme that it shouldn't be sensitive to secret text legth?
Well, Vadym already mentioned that Shamir Secret Sharing should be done in a Finite Field; however it doesn't address your question.
With Shamir's Scheme, a single instance can share any value between $0$ and $p^k - 1$ (where $p^k$ is the size of the finite field you use [1]). And, with Shamir, there is no security difference between the various finite fields, hence we can pick one based on practical concerns (e.g. the number of secrets you want to be able to issue, the size of the secret, the easy of implementing the various finite field operations).
However, what you want to do is share a password as the secret; that password is fairly long, and is of variable length. Well, there are two obvious alternatives:
- Pick a $p^k$ (or prime $p$ if you go with $k-1$) that's large enough to hold any password you want to share; for example, if you use $p=2^{521}-1$ (which is prime), you can share passwords up to 65 characters in length. This works, however the disadvantage is that values this large would need to be handled with a bignum library. If you are using a language with a bignum library built-in (for example, Python), this is not an issue - if not, it'd probably be easier to go with the second idea.
With this idea, if we had the password 'letmein' (0x6c 0x65 0x74 0x6d 0x65 0x69 0x6e in ASCII), we might encode that as the integer 0x6c65746d65696e = 30510848210725230.
- Split the password up into multiple secrets, and share each secret separately. For example, for a 14 character password, we can split that up into 14 separate secrets (with each secret being one character from the password), and share each character using $p=257$ and $k=1$ (so each party would get a total of 14 shares, one share for each of the 14 characters). With this idea, it is safe to use the same identifier for all the shares a party gets; however it is important that each secret is generated using independent randomness (that is, each of the 14 random polynomials is generated separately).
With this idea, we would encode the password 'letmein' as the 8 independent secrets 0x6c 0x65 0x74 0x6d 0x65 0x69 0x6e
With this second idea, if you don't want to leak the length of the secret, what you can do is always share a fixed number of secrets (which will be the maximum length of password you can share, say, 32), and for passwords shorter than that, fill in the additional secret characters with a value that cannot occur in a real password (for my example of $p=257$, the obvious value to use would be $256$).
[1]: For any prime $p$ and any integer $k$, there is a finite field of size $p^k$. It would probably be easier for you to start with using a field with $k=1$ and $p$ an appropriate-sized prime - this makes the addition, subtraction and multiplication operations a lot closer to the standard algorithms you are familiar with (division is still wonky).