A method of generating discovery code, used by a network entity (254, 274), characterized in the generating method comprising: selecting a first substring in a Proximity-based Services, ProSe, application code of an announcing User Equipment by choosing a plurality of first bits within a continuous range of the ProSe application code of the announcing UE and a second substring in a ProSe application code of a monitoring UE by choosing a plurality of second bits within the continuous range of the ProSe application code of the monitoring UE for a device to device, D2D, discovery, wherein the ProSe application code comprises a public land mobile network identifier of a ProSe function in the network and a temporary identifier; generating a matching string and a non-matching string according to the first substring associated with the announcing UE and the second substring associated with the monitoring UE by: generating the matching string in which a first bitwise AND operation output between the first substring and the matching string matches a second bitwise AND operation output of the second substring and the matching string; and generating the non-matching string in which a third bitwise AND operation output between the first substring and the non-matching string does not match a fourth bitwise AND operation output of the second substring and the non-matching string; and generating a ProSe application mask according to the matching string and the non-matching string; wherein one of the matching string and the non-matching string is set as a part of the ProSe application mask. selecting a first substring in a Proximity-based Services, ProSe, application code of an announcing User Equipment by choosing a plurality of first bits within a continuous range of the ProSe application code of the announcing UE and a second substring in a ProSe application code of a monitoring UE by choosing a plurality of second bits within the continuous range of the ProSe application code of the monitoring UE for a device to device, D2D, discovery, wherein the ProSe application code comprises a public land mobile network identifier of a ProSe function in the network and a temporary identifier; generating a matching string and a non-matching string according to the first substring associated with the announcing UE and the second substring associated with the monitoring UE by: generating the matching string in which a first bitwise AND operation output between the first substring and the matching string matches a second bitwise AND operation output of the second substring and the matching string; and generating the non-matching string in which a third bitwise AND operation output between the first substring and the non-matching string does not match a fourth bitwise AND operation output of the second substring and the non-matching string; and generating the matching string in which a first bitwise AND operation output between the first substring and the matching string matches a second bitwise AND operation output of the second substring and the matching string; and generating the non-matching string in which a third bitwise AND operation output between the first substring and the non-matching string does not match a fourth bitwise AND operation output of the second substring and the non-matching string; and generating a ProSe application mask according to the matching string and the non-matching string; wherein one of the matching string and the non-matching string is set as a part of the ProSe application mask.